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