0

I am at the final step of a webpage deployment using jstl and java. It uses a file uploader to upload pictures for users who can then display them on a home page. I am stuck at this step. This is my code:

File uploadDir = new File("/opt/tomcat/webapps/PictureSquirrell/pics/");

                    for (Part part : request.getParts()) {
                        fileName = getFileName(part);
                        part.write(uploadDir + fileName);
                    }

                    File file = File.createTempFile(fileName, ".png", uploadDir);
                    item.write(file);

I want the picture to upload in the pics file on a ubuntu server. however, when I upload the file, it uploads to:

/opt/tomcat/webapps/PictureSquirrell/pics\filename.png

So it gets stored in the project root as opposed to the folder called pics in the project root. Can somebody please help?

Thanks!

Answer

Remove the final forward slash from:

File uploadDir = new File("/opt/tomcat/webapps/PictureSquirrell/pics/");

So it should be

File uploadDir = new File("/opt/tomcat/webapps/PictureSquirrell/pics");
  • show full path where you store picture in your project – Binod Pant Jul 10 '17 at 18:32
  • If `/opt/tomcat/webapps/PictureSquirrell/pics/filename.png` is not the correct path of an uploaded file, what would be an example of a correct path? – VGR Jul 10 '17 at 19:21
  • Sorry, /opt/tomcat/webapps/PictureSquirrell/pics/filename.png is the correcct path, the proble is when it goes to upload the file, it stores it in the PictureSquirrell folder and names it pics\filename.png as opposed to uploading it to the pics folder as filename.png – Donnacha Holmes Jul 11 '17 at 12:11

0 Answers0