Help needed!
I am using this article to upload a file in my project http://www.theserverside.com/news/1365153/HttpClient-and-FileUpload
Using this article I am able to upload the file but the file gets uploaded in my /home/parinati/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/CMTint/
i.e. The eclipse tomcat webapps folder.
But I want my file to be uploaded in my project folder. When I do request.getContextPath() the output is CMTint/ and I want the file to get uploded into CMTint/Uploads/
My upload code is -->
System.out.println("Content Type ="+request.getContentType());
DiskFileUpload fu = new DiskFileUpload();
// If file size exceeds, a FileUploadException will be thrown
fu.setSizeMax(1000000);
List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();
while(itr.hasNext()) {
FileItem fi = (FileItem)itr.next();
//Check if not form field so as to only handle the file inputs
//else condition handles the submit button input
if(!fi.isFormField()) {
System.out.println("nNAME: "+fi.getName());
System.out.println("SIZE: "+fi.getSize());
//System.out.println(fi.getOutputStream().toString());
File fNew= new File(application.getRealPath("/"), fi.getName());
System.out.println(fNew.getAbsolutePath());
fi.write(fNew);
}
else {
System.out.println("Field ="+fi.getFieldName());
}
}
Can you suggest what changes are required. Any help will be greatly appreciated.
Thanks in advance Sweta