Solved

saving a .jpg http parameter

Posted on 1998-08-07
4
230 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now