[英]How to receive 2 binary files and JSON in Jersey jax-rs?
I need to build a service that can receive 2 binary files (~100k each) and some metadata, preferably in json. 我需要构建一个可以接收2个二进制文件(每个〜100k)和一些元数据的服务,最好是json。
I found this , but it only seems to provide one InputStream to one of the parts. 我发现了这一点 ,但似乎只为其中一部分提供了一个InputStream。 But I'd need two.. so what to do?
但是我需要两个..那该怎么办?
You have a few options 您有几种选择
Simply add another parameter(s) with a different part annotation 只需添加带有不同零件注释的另一个参数
@POST @Consumes("multipart/form-data") public Response post(@FormDataParam("file1") InputStream file1, @FormDaraParam("file2") InputStream file2) { }
The parts can have the same part name, so you could do 零件可以具有相同的零件名称,因此您可以
@POST @Consumes("multipart/form-data") public Response post(@FormDataParam("file") List<FormDataBodyPart> files) { for (FormDataBodyPart file: files) { FormDataContentDisposition fdcd = file.getFormDataContentDisposition(); String fileName = fdcd = getFileName(); InputStream is = file.getValueAs(InputStream.class); } }
You could traverse the entire multipart body youself 您可以自己遍历整个多部分身体
@POST @Consumes("multipart/form-data") public Response post(FormDataMultiPart mulitPart) { Map<String, List<FormDataBodyPart>> fields = multiPart.getFields(); }
See Also: 也可以看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.