1

I have a litte trouble with unzipping a zip file when I upload it as multipart with jersey client. To upload the file I use this code:

FormDataMultiPart form = new FormDataMultiPart().field("file", file,
                MediaType.MULTIPART_FORM_DATA_TYPE);
   service.path(DSCRM_IMPORT_UPLOAD).type(MediaType.MULTIPART_FORM_DATA)
                .accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, form);

service is a WebResource.

On the server side my code looks like this:

@Path("/upload")
    @Consumes("multipart/form-data")
    @POST
    public Response importData(@FormDataParam("file") InputStream file)
            throws Exception {
        File newFile = new File("/temp.zip");
        final OutputStream out = new FileOutputStream(newFile);
        try {
            ByteStreams.copy(file, out);
        } finally {
            out.close();
        }

        ZipFile zip = new ZipFile(newFile);

On calling new ZipFile I always get an error when opening the zip file and I was wondering why. So I tried to output the stream to a string ang got the following result: --Boundary_1_3753023_1334078932448 Content-Type: multipart/form-data Content-Disposition: form-data; name="file" ... ZIP CONTENT ... --Boundary_1_3753023_1334078932448--

So my guess is, that the --Boundary ... --Boundary_1_3753023_1334078932448-- makes my zip file corrupt so it is not possible to open it.

Do I use the multipart correctly? Or how can I get rid of the --boundary stuff to succesfully unzip my file... (I know the --boundary stuff is correct for a multipart post, but somehow it must be possible to just get the content of the post...)

If you need any further information, just let me know and I'll post it.

Thx in advance!

TJ

TerenceJackson
  • 1,776
  • 15
  • 24
  • Boundaries should go away, of course. Just as hint: why cannot use use `@FormDataParam("file") FormDataContentDisposition d` on server? Then you have file name directly, you don't need to copy anything. – dma_k Apr 11 '12 at 18:06
  • when I do public void importData(@FormDataParam(IMPORT_FILE_FORM_NAME) FormDataContentDisposition file)throws Exception {....} I get the following exception: org.jboss.resteasy.spi.BadRequestException: Could not find message body reader for type: class com.sun.jersey.core.header.FormDataContentDisposition of content type: multipart/form-data;boundary="Boundary_1_4512144_1334175005299" – TerenceJackson Apr 11 '12 at 20:11

0 Answers0