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).
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).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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 :-) ]
JSDK 2.0: http://www.w3.org/Jigsaw. [I didn't tried it myself up to now, but it looks like I will :-) ]
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"
byte JPGData[] = JPGStr.getBytes(); // String -> byte conversion
then save the byte array in a file.
Tell me if this is an answer.