commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Forte, Graham" <graham.fo...@ngc.com>
Subject [File Upload] specifying the directory to upload to
Date Tue, 30 Mar 2004 17:50:45 GMT
I am trying to use commons 1.0 final to accomplish file uploads. So far it works. I need to
have the upload directory be a directory other than the webapps/myapp/ directory. I initially
specified the directory using: upload.setRepositoryPath("C:\\data\\");
This worked initially(except that it renamed the file to upload_00000024.tmp) but then stopped
working and I cant figure out what I did to make it stop. I am using a jsp to upload the files
and it is similar to the commons example. Currently it is uploading the file to the app root
directory webapps/myapp/  in tomcat 4.1. 
Any help is appreciated.

Here is my code:
commons.jsp


boolean isMultipart = FileUpload.isMultipartContent(request);

DiskFileUpload upload = new DiskFileUpload();

upload.setRepositoryPath("C:\\data\\");
upload.setSizeMax(-1);

List items = upload.parseRequest(request);

Iterator itr = items.iterator();

while(itr.hasNext()) {
	FileItem item = (FileItem) itr.next();
        
	if(item.isFormField()) {
            
	String fieldName = item.getFieldName();

	} else {

		File fullFile  = new File(item.getName());  
		File savedFile = new File(getServletContext().getRealPath("/"),fullFile.getName());
		item.write(savedFile);
	}
} 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message