users@jersey.java.net

[Jersey] Problem about file upload when using _at_FormDataParam

From: michael_cheng <chengyan927_at_hotmail.com>
Date: Thu, 3 Dec 2009 06:49:20 -0800 (PST)

Hi,
It's about file upload when my project using jax-rs.I followed the code
which the @FormDataParam API mentioned.
Please help me about this issue.

My client code:
<form action="http://localhost:8080/testImage" method="post"
enctype="multipart/form-data">
<input type="file" name="picture" />
<input type="submit" value="Send" />
</form>

My server code:
@POST
@Path("testImage")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void getImage(
            @FormDataParam("file") InputStream in) throws IOException{
                         OutputStream os = new FileOutputStream(new
File("D:\\good.jpg"));
                byte[] b = new byte[in.available()];
                int i = 0;
                while ((i = in.read(b)) >0) {
                        os.write(b, 0, i);
                }
                os.flush();
                os.close();
                in.close();
        }

When i upload a picture,the file "D:\\good.png" will show,and the fileSize
is as the same .But I can not see the image when I open it.
When debuging the program,I noticed that the InputStream contains both the
file itself and the file description.Just
like"----------789652236442--Content Type=jpg/image........xxxxxxxxxxxx(file
itself)----78965222--".
And my question is how can I just get the file itself in InputStream?Or I
missed something?
I will so appreciated if getting your help.Thanks.
-- 
View this message in context: http://n2.nabble.com/Problem-about-file-upload-when-using-FormDataParam-tp4106463p4106463.html
Sent from the Jersey mailing list archive at Nabble.com.