I am building a JSF2.2 web application and server is GlassFish V5. I am looking to configure the directly where I could store the files uploaded my the users of the website.
I am using the following code to store the files in the server's (Mac) path of /var/gdf
(gdf
being the web app's context name).
The code that fails is part.write("/var/gdf/"+getFileName(part));
where part
is an instance of javax.servlet.http.Part;
And the code for getFileName(part)
is as follows:-
private static String getFileName(Part part){
String filename=null;
for (String cd : part.getHeader("content-disposition").split(";")) {
if (cd.trim().startsWith("filename")){
filename=cd.substring(cd.indexOf('=')+1).trim();
}
}
return filename;
}
However, with each reboot of the Glassfish server, I see the following error on the logs:
Severe: java.io.FileNotFoundException: /Users///glassfish5/glassfish/domains/domain1/generated/jsp/gdf/var/gdf/2O4A1012.JPG (No such file or directory)
Any suggestion would be highly appreciated.