我正在尝试实现一个能够处理以下POST的REST端点:
-----------------------------6739772541706953700536795627
Content-Disposition: form-data; name="flowChunkNumber"
1
-----------------------------6739772541706953700536795627
Content-Disposition: form-data; name="flowChunkSize"
1048576
-----------------------------6739772541706953700536795627
Content-Disposition: form-data; name="flowCurrentChunkSize"
1474992
-----------------------------6739772541706953700536795627
Content-Disposition: form-data; name="flowTotalSize"
1474992
-----------------------------6739772541706953700536795627
Content-Disposition: form-data; name="flowIdentifier"
1474992-SAM_0391JPG
-----------------------------6739772541706953700536795627
Content-Disposition: form-data; name="flowFilename"
SAM_0391.JPG
-----------------------------6739772541706953700536795627
Content-Disposition: form-data; name="flowRelativePath"
SAM_0391.JPG
-----------------------------6739772541706953700536795627
Content-Disposition: form-data; name="flowTotalChunks"
1
-----------------------------6739772541706953700536795627
Content-Disposition: form-data; name="file"; filename="SAM_0391.JPG"
Content-Type: application/octet-stream
因此,我尝试利用org.glassfish.jersey.media.multipart.FormDataMultiPart,如下所示:
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadImage(FormDataMultiPart multiPartData).
此时我正在寻找检索Content-Type:application / octet-stream的实际内容。有关如何处理此类内容的任何建议吗?
提前致谢
答案 0 :(得分:0)
You could just use the @FormDataParam
annotations
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadImage(@FormDataParam("file") InputStream file)
Or if you want to stick to using FormDataMultiPart
, you could do something like
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadImage(FormDataMultiPart multiPartData) {
FormDataBodyPart filePart = multiPartData.getField("file");
if (filePart != null) {
InputStream file = filePart.getEntityAs(InputStream.class);
}
}
See:
FormDataMultiPart
to get an idea of other things you can do programmatically.