Link to home
Start Free TrialLog in
Avatar of arakawa
arakawa

asked on

saving a .jpg http parameter

i am trying to save the contents of a .jpg file passed to a java servlet as a multipart/form-data http parameter.
the parameter comes in as a ServletInputStream, an extension of InputStream, using the getLine command to
copy the contents of the stream into a byte array.  I am then sending the byte array to a  FileOutputStream.  is
there any reason why this wouldn't work? (because it doesn't).
Avatar of fontaine
fontaine

If I understand well, you are trying to upload a JPEG to the server. I don't really understand
the method you are using. Here is to way I would go:

Let req be the HttpServletRequest instance passed to the doPost() method and JPGFile
the name of the parameter in the HTML form (i.e. you have something like this in the HTML:
<INPUT NAME="JPGFile" TYPE="file">. The servlet code will look like:

String JPGStr = req.getParameter("JPGFile"); // the whole content of the file as a String
byte JPGData[] = JPGStr.getBytes(); // String -> byte conversion

then save the byte array in a file.

Tell me if this is an answer.
ASKER CERTIFIED SOLUTION
Avatar of fontaine
fontaine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arakawa

ASKER

actually, i am using Acme.Serve which does not implement a doPost() method in
the HttpServletRequest class nor can you getParameter() if it is a multipart/form-data
parameter being passed.
I think that Jigsaw could be a good alternative if you are searching for a free server supporting
JSDK 2.0: http://www.w3.org/Jigsaw.  [I didn't tried it myself up to now, but it looks like I will :-) ]