Headers included in byte array at server
hobbeschild opened this issue · comments
My server-side implementation receives the chunks of a ZIP as byte arrays:
@POST
@Path("/uploadThing")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public ThingResponse uploadThing(final @Context() ContainerRequestContext p_Context, byte[] p_RawData) {
return new ThingResponse(p_Context, p_RawData);
}
I concatenate all the chunks to a single byte array and save it against a business object in an Oracle table.
When I download the ZIP using this code and MediaType.APPLICATION_OCTET_STREAM:
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(p_OutputStream);
bufferedOutputStream.write(thingBO.getRawData());
then the resulting ZIP cannot be opened. Looking at it in Notepad++, the new ZIP is almost exactly the same as the original, except that at the top it has this (before the first "PK" of the ZIP bytes):
------WebKitFormBoundaryXSHBfDH8JAH20815
Content-Disposition: form-data; name="file"; filename="blob"
Content-Type: application/octet-stream
If I remove these 3 lines and save then I can open the ZIP fine and it exactly matches the original.
How can I stop it from adding these 3 lines?
They were not added when I uploaded the ZIP file directly, without your code, but some ZIP files are too big so I do need it. (I was doing a JSON post with the byte[] as one property of an object parameter.)
Many thanks.
I have fixed it, by annotating the second parameter with the name of the file parameter!
@FormDataParam("file") byte[] p_RawData