Solved

saving a .jpg http parameter

Posted on 1998-08-07
4
240 Views
Last Modified: 2013-11-24
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).
0
Comment
Question by:arakawa
  • 3
4 Comments
 
LVL 5

Expert Comment

by:fontaine
ID: 1231600
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.
0
 
LVL 5

Accepted Solution

by:
fontaine earned 50 total points
ID: 1231601
    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.
0
 

Author Comment

by:arakawa
ID: 1231602
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.
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1231603
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 :-) ]
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 213
servlet web applications   metadata-complete="true" or false 3 119
jboss 7.1 start up error 1 39
Chrome and Firefox Java 5 51
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question