Thankyou very much for your answer. I'll try to explain better what is my trouble.
Suppose I have a file called imagine.gif on a c:\mydir, so the path to the latter file is c:\mydir\imagine.gif.
Well, now I need to upload imagine.gif into a server directory called /img (note: I'm using Tomcat 5.0) that is into the
%TOMCAT_HOME%/webapps/myProject. I think that at this point is all easy clear (isn't so?).
Now how I have to write the code to do that?
<!-- extract from previous code -->
if(!fitem.isFormField()){
//this give me c:\mydir\imagine.gif - so, with the file full path
System.out.println(fitem.getName());
//here i build the file to upload
File uploadFile = new File(fitem.getName());
//here I overwrite the file I intend to upload
//I don't know how to write code to put it into the server folder
fitem.write(uploadFile);
}Hoping this help me and u to better anderstand the problem, Tanks in advaice
Omar
----- Original Message ----- From: "Martin Cooper" <[EMAIL PROTECTED]>
To: "Jakarta Commons Users List" <[EMAIL PROTECTED]>
Sent: Tuesday, September 28, 2004 5:20 AM
Subject: Re: [FileUpload] How to specify the destination of the upload
I'm not clear on whether you're asking about the path to the file the user selected for upload, or about the location of the file after it has been uploaded.
In the first case, whether or not you get the full path to the file the user selected is up to the browser. Most browsers provide only the base file name, and not the full path. This is primarily for security reasons - it's not a good idea to expose the user's local file system to the server. Some browsers do, however, provide the full path.
In the second case, you simply need to decide for yourself where you want the file to be written, and then pass that to the FileItem.write() method. You don't want to do what you have in the code you provide, since that just takes whatever the browser provided for the file name. If that provides a path, then it could try to write anywhere on the server and you are not checking where that might be. If it doesn't provide a path, then it's going to be written in whatever the web container deems to be the current working directory, which is also probably not what you want.
-- Martin Cooper
On Mon, 27 Sep 2004 12:11:57 +0200, Omar Adobati <[EMAIL PROTECTED]> wrote:This is the code I've write to perform a fileupload.
It's seems to work nice but there is a definitive problem... I don't know, and can't understand, how i can specify the destination path to the file I need to upload.
I'm using commons fileUpload package...
Does anybody can help me?
Tanks in advice, Omar (from Italy)
---
boolean isMultipart = FileUpload.isMultipartContent(request); if(isMultipart){ DiskFileUpload upload = new DiskFileUpload();
List item = upload.parseRequest(request); Iterator iter = item.iterator(); while(iter.hasNext()){ DefaultFileItem fitem = (DefaultFileItem)iter.next(); if(fitem.isFormField()){ out.println(fitem.getFieldName()); out.println(fitem.getName()); out.println(fitem.getSize()); out.println(fitem.getString()); } if(!fitem.isFormField()){ out.println(fitem.getFieldName() + "<br>"); out.println(fitem.getName() + "<br>"); out.println(fitem.getSize() + "<br>"); out.println(fitem.getContentType() + "<br>"); out.println(fitem.isInMemory() + "<br>"); File uploadFile = new File(fitem.getName()); fitem.write(uploadFile); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
