Solved

saving a .jpg http parameter

Posted on 1998-08-07
4
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

627 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