commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Schalk" <sch...@volume4.co.za>
Subject RE: [File Upload] specifying the directory to upload to
Date Tue, 30 Mar 2004 20:37:38 GMT
Graham

I use this piece of code to get the filename:

StringTokenizer tokenizer = new StringTokenizer(fileName, "\\, :, /");

            int amount = tokenizer.countTokens();             
            for (int i = 0; i < amount -1; i++) {
                tokenizer.nextToken();        
            }               
            String currentFile = tokenizer.nextToken();

Kind Regards
Schalk Neethling
Web Developer.Designer.Programmer.President
Volume4.Development.Multimedia.Branding
emotionalize.conceptualize.visualize.realize
Tel: +27125468436
Fax: +27125468436
email:schalk@volume4.co.za
web: www.volume4.com
 
This message contains information that is considered to be sensitive or
confidential and may not be forwarded or disclosed to any other party
without the permission of the sender. If you received this message in error,
please notify me immediately so that I can correct and delete the original
email. Thank you. 

:: -----Original Message-----
:: From: Forte, Graham [mailto:graham.forte@ngc.com]
:: Sent: Tuesday, March 30, 2004 10:27 PM
:: To: 'Jakarta Commons Users List'
:: Subject: RE: [File Upload] specifying the directory to upload to
:: 
:: Yes , I got it from onjava.com
:: 
:: Should I not use it like that?
:: 
:: Thanks, Graham
:: 
:: -----Original Message-----
:: From: Schalk [mailto:schalk@volume4.co.za]
:: Sent: Tuesday, March 30, 2004 1:48 PM
:: To: 'Jakarta Commons Users List'
:: Subject: RE: [File Upload] specifying the directory to upload to
:: 
:: 
:: Graham
:: 
:: With this line:
:: File currentFile = new
:: File(getServletContext().getRealPath("/"),fullFile.getName());
:: 
:: You are probably trying to get the name of the file being uploaded
without
:: any folder or separator information, correct?
:: 
:: Kind Regards
:: Schalk Neethling
:: Web Developer.Designer.Programmer.President
:: Volume4.Development.Multimedia.Branding
:: emotionalize.conceptualize.visualize.realize
:: Tel: +27125468436
:: Fax: +27125468436
:: email:schalk@volume4.co.za
:: web: www.volume4.com
:: 
:: This message contains information that is considered to be sensitive or
:: confidential and may not be forwarded or disclosed to any other party
:: without the permission of the sender. If you received this message in
error,
:: please notify me immediately so that I can correct and delete the
original
:: email. Thank you.
:: 
:: :: -----Original Message-----
:: :: From: Forte, Graham [mailto:graham.forte@ngc.com]
:: :: Sent: Tuesday, March 30, 2004 9:41 PM
:: :: To: 'Jakarta Commons Users List'
:: :: Subject: RE: [File Upload] specifying the directory to upload to
:: ::
:: :: Schalk thanks for your reply.
:: :: That was helpful, however I am now getting a nullpointerexception
which
:: points to:
:: ::
:: :: java.lang.NullPointerException
:: :: 	at
:: ::
::
org.apache.commons.fileupload.DefaultFileItem.write(DefaultFileItem.java:442
:: )
:: ::
:: :: I am sure it is in the way I implemented the File(File parent, String
:: child) object. As
:: :: below:
:: ::
:: :: File fullFile  = new File(item.getName());
:: :: File currentFile = new
:: File(getServletContext().getRealPath("/"),fullFile.getName());
:: :: String curFile = currentFile.toString();
:: :: File diskFile = new File(folder, curFile); // to pass the folder and
file
:: to be uploaded
:: :: item.write(diskFile); // This line writes the file to disk.
:: ::
:: :: I think I am declaring currentFile improperly.
:: :: Any ideas?
:: ::
:: :: -----Original Message-----
:: :: From: Schalk [mailto:schalk@volume4.co.za]
:: :: Sent: Tuesday, March 30, 2004 12:14 PM
:: :: To: 'Jakarta Commons Users List'
:: :: Subject: RE: [File Upload] specifying the directory to upload to
:: ::
:: ::
:: :: Graham
:: ::
:: :: This is the line where you specify the folder:
:: :: You can set the String folder = "folder/to/upload/to/"; at the top of
the
:: :: JSP and then use this line:
:: ::
:: :: File diskFile = new File(folder, currentFile); // to pass the folder
and
:: :: file to be uploaded
:: :: item.write(diskFile); // This line writes the file to disk.
:: ::
:: :: The setRepositoryPath you were you specify your temp folder. This
folder
:: is
:: :: used to temporarily store file data before it is written to disk if
:: :: setSizeThreshold is exceeded.
:: ::
:: :: Kind Regards
:: :: Schalk Neethling
:: :: Web Developer.Designer.Programmer.President
:: :: Volume4.Development.Multimedia.Branding
:: :: emotionalize.conceptualize.visualize.realize
:: :: Tel: +27125468436
:: :: Fax: +27125468436
:: :: email:schalk@volume4.co.za
:: :: web: www.volume4.com
:: ::
:: :: This message contains information that is considered to be sensitive
or
:: :: confidential and may not be forwarded or disclosed to any other party
:: :: without the permission of the sender. If you received this message in
:: error,
:: :: please notify me immediately so that I can correct and delete the
:: original
:: :: email. Thank you.
:: ::
:: :: :: -----Original Message-----
:: :: :: From: Forte, Graham [mailto:graham.forte@ngc.com]
:: :: :: Sent: Tuesday, March 30, 2004 7:51 PM
:: :: :: To: 'Jakarta Commons Users List'
:: :: :: Subject: [File Upload] specifying the directory to upload to
:: :: ::
:: :: :: 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
:: ::
:: ::
:: ::
:: :: ---------------------------------------------------------------------
:: :: To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
:: :: For additional commands, e-mail: commons-user-help@jakarta.apache.org
:: ::
:: :: ---------------------------------------------------------------------
:: :: To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
:: :: For additional commands, e-mail: commons-user-help@jakarta.apache.org
:: 
:: 
:: 
:: ---------------------------------------------------------------------
:: To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
:: For additional commands, e-mail: commons-user-help@jakarta.apache.org
:: 
:: ---------------------------------------------------------------------
:: To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
:: For additional commands, e-mail: commons-user-help@jakarta.apache.org



---------------------------------------------------------------------
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