【发布时间】:2017-09-12 09:53:18
【问题描述】:
我想除了提供一个 File 对象之外,没有其他方法可以创建 FileDateBodyPart:
public FileDataBodyPart(String name, File fileEntity)
但就我而言,我拥有的是一个字节[],我不想将其转换为文件并存储在文件系统中。
在最坏的情况下使用其他客户端库从字节数组、输入流...生成多部分(上传文件时)有没有其他方法?
更新: 这是工作代码(但我想使用 byte[] 而不是 File):
FileDataBodyPart filePart = new FileDataBodyPart("attachment", new File("C:/TEMP/test.txt"));
MultiPart multipart = new FormDataMultiPart().bodyPart(filePart);
Invocation.Builder invocationBuilder = webTarget.request().accept(MediaType.APPLICATION_JSON);
Response response = invocationBuilder
.buildPost(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA))
.invoke();
【问题讨论】:
-
这个问题还不清楚。显示更多代码。你的意图是什么?
-
问题已更新。
标签: java rest jersey client multipart