• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Apache commons file upload does not work for me.

 
Led Estonilo
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ankit Garg
Sheriff
Posts: 9520
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to upload your file in a directory upload inside your web application's directory structure, then use ServletContext.getRealPath...
 
Led Estonilo
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i need to get first application directory structure

string thedirectory = ServletContext.getRealPath()

then

fi.write(new file(theDirectory, fileName)); ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic