aspose file tools*
The moose likes Servlets and the fly likes Apache commons file upload does not work for me. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Apache commons file upload does not work for me." Watch "Apache commons file upload does not work for me." New topic
Author

Apache commons file upload does not work for me.

Led Estonilo
Ranch Hand

Joined: Jan 06, 2009
Posts: 36
this is my code that ive done reading the API of apache commons file upload.



and the html code




the problem is it does not do anything. i mean yes i see the ouput messages of

out.print("<p>the file"+ fileName +" is uploaded</p1>");
out.print("<p> with"+ fileSize +" bytes</p>");
out.print("<p>Success!</p1>");

and also it outputs info of fileName and filSize but still i have not seen any copy of the file upload. Have i done something wrong here?


i like to add that when i change

fi.write(new File(fileName)); to fi.write(new File("/upload",fileName));

it yields an error. It says it cant find the specified file "/upload/anyfile.txt" (where anyfile.txt is the uploaded file)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41872
    
  63
Do you really have a root directory called "/upload"?

If you use "new File(fileName)", then that's a relative path which doesn't work in a web app; use an absolute path instead.


Ping & DNS - my free Android networking tools app
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

If you want to upload your file in a directory upload inside your web application's directory structure, then use ServletContext.getRealPath...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Led Estonilo
Ranch Hand

Joined: Jan 06, 2009
Posts: 36
so i need to get first application directory structure

string thedirectory = ServletContext.getRealPath()

then

fi.write(new file(theDirectory, fileName)); ?
 
jQuery in Action, 2nd edition
 
subject: Apache commons file upload does not work for me.