I'm trying to give the user the ability to choose which directory they want to store a file. On my web page I have a input field "subdir" which I want to pass the contents Upload.java: MultipartRequest multi = new MultipartRequest(req, subdir, maxsize); How do I pass or parse "subdir" the value. Thanks Greg
Nothing in the HTTP spec says that form fields need to be submitted in the order in which they appear in the HTML source. So there is no guarantee as you are parsing the fields, that your 'source dir' would even come before your file upload.
The solution would be to upload the files to a constant temp directory, parse the request, and use the supplied value for 'directory' and Java File I/O methods to move the file after upload.
This is even covered in the cos FAQ as the preferred method of doing file uploads to dynamic directories ( http://www.servlets.com/cos/faq.html ) search that page for the word 'safest' [This message has been edited by Mike Curwen (edited December 10, 2001).]
Hi Greg, I also encounter the same situation. The problem with MultipartRequest is that the uploading is done in the Constructor. The "SubDir" parameter cannot be retieved using MultipartRequest.getParamater() if the instance is not constructed. However to create the MultipartRequest object, the "SubDir" parameter is needed. What I did is that I modify the MultipartRequest class so that the Uploading of files is invoked by a seperate method. The MutipartRequest class does not take in the "SaveDiectory" in its constructor. I added the methods setDir() and uploadFiles() to the class. So my UploadTest class uses the MultipartRequest in the following way: MultipartRequest multi = new MultipartRequest(req, 5 * 1024 * 1024); multi.setDir(multi.getParameter("subdir")); multi.uploadFiles(multi.getDir()); Hope it helps.
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad: