Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

saving a .jpg http parameter

Posted on 1998-08-07
4
Medium Priority
?
252 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 150 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

688 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