MultipartRequest-- cannot get the name of the file to upload
843840Mar 30 2002 — edited Mar 26 2004Hi,
I am using oreilly's MulitpartRequest to upload a file, however I am having difficutly trying to get the actual Name of the file itself. I am using the following code. I only have one file to upload so it is a little different from the examples I have seen. I am using MultipartRequest getParameter method to get the values from the other form fields..
File fileNm = null;
...
//this is inside my doPost()
MultipartRequest multi = new MultipartRequest(request, "C:\\files", 50 * 1024);
String strIndustry = multi.getParameter("frmIndustry");
String strCompany = multi.getParameter("frmCompany");
String strCollabType = multi.getParameter("frmCollaboration")
String strFileSource = multi.getParameter("frmFileSource");
fileNm = new File(strFileSource);
displayfileNm = fileNm.getName();
String file = multi.getFilesystemName(strFileSource);
File f = multi.getFile(strFileSource);
....
//then I am testing to see what I get using this.
output.println("File name: " + displayfileNm + "<br>");
output.println("File name: " + file + "<br>");
I know there are many ,many posts about using MulitpartRequest but I have not been able to find a resolution or answer to this problem. The servlet compiles, but when I try to run it I get::
java.lang.NullPointerException
at java.io.File.(File.java:180)
at FileUpload.doPost(FileUpload.java:67)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
etc.......
Any idea why I am not getting the file name??
Any help would be greatly appreciated.
Thanks