Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in streaming & creating files using FileOutputStream  RSS feed

 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am having two image files with its size.
Now what i want to do is ,i want to send the file size & then the whole data of the file to a servlet.

What i am doing is on the client side:

Opening the connection to that file
Getting the fileSize
Opening the httpConnection to the servlet
opening an outputstream on that httpconnection
writing the file size to that outputstream.
closing all the connection & streams.

Then again doing the same procedure mentioned above for writing the file data to the output stream.

On the server side that is in the servlet iam doing the following:

Opening an DataInputstream dis = new DataInputstream(request.getInputStream )
int i = dis.readInt();
Closing the inputstream

Then again for reading the file data coming from the client side I am opening another DataInputStream,reading the whole data coming into an byte[] array & then closing the inputstream.


But the servlet side its throwing IO exception:Could not read the whole file or EOF exception.

So please tell me where i am going wrong.
I want to have both the filesize & the data of the file available to the servlet.

One more thing :
With my request i have two files. For sending the data of both the files to servlet, if the data is successfully received by the servlet & if i want to create individual files for both of them on the server file system using FileOutputStream how can i achieve this.

I tried to give a String path with a counter appended to it & provided that String to the FileOutputStream constructor.
But the server is giving the exception that system cannot find the path specified.
On the other hand what is specified is that if the file doesn't exist it gets created.
One file with a path like "C:/Images" i am able to create but different files are not getting created for both the files whose data i am sending in my request.
So how to solve this problem.

Thanking you,
jignesh
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd bet closing and opening connections and streams is not doing what you expect. By reading and writing the streams this way you're going around HTTP standards. Look into a more standard approach maybe with the Apache HTTPClient and FileUpload packages.
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for the reply.
The httpclient & fileupload are mostly for Html forms on the client side.
But the image fileswhich i want to send are in the mobile phones whose data i am getting by interacting with the filesystem of the phone .

So what can i do regarding this???

Thanks
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!