wood burning stoves 2.0*
The moose likes Servlets and the fly likes File upload problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "File upload problem " Watch "File upload problem " New topic
Author

File upload problem

eddy johns
Ranch Hand

Joined: Feb 16, 2010
Posts: 67
Hi everyone,

Can anyone please try to run the following code and see if it works? There's a FileUpload.html, calling a FileUpload.jsp, calling the FileUpload.java file and all of them do one simple thing: upload a file from the file system and write it to a location you specify. This is simple stuff and it works on my windows development machine but for some reason this code - or rather an identical one inside a larger application - fails on the client's deployment server (which is a unix machine.) It seems to read only two thirds of the image to the dataBytes array and then stops, and later in the code throws an IndexOutOfBounds exception. It writes the uploaded file to the correct path and with the correct name but with 0 bytes. This is baffling to me and I would really appreciate some help.

One possible reason that I can think of: the directory it needs to write to on the client's server is virtual, and running on a separate file server. Could this be the problem?

I apologize for posting this question a second time but I got no replies the first one and now I'm including all the relevant code. To run it you'll need to change the serverPath in the jsp file to a path on your machine.

Thank you very much for your help!
Eddy


Here are the files:









David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Nothing to do with ORM; moving to servlets.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why wouldn't you just use an existing library to do all the busywork, like commons-fileupload?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

David is right -- no experienced web developer is going to re-invent the wheel. See the JSP FAQ for information on the available libraries.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
eddy johns
Ranch Hand

Joined: Feb 16, 2010
Posts: 67
I implemented the commons-fileupload and it works beautifully. Thank you very much, David and Bear!!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Glad you got it working--that's great!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File upload problem
 
Similar Threads
file upload works on windows, doesn't on unix
problem in uploading a file
request cannot be resolved. any imports missing??
error in uploading zip file
Problem with uploading images