我有一个服务中的以下方法:
public interface MyService {
@POST
@Path("/upload-file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
void uploadFile(@FormDataParam("file") InputStream inputStream,
@FormDataParam("file") FormDataContentDisposition contentDisposition);
}
我使用WebResourceFactory创建此接口的一个实例:
final MyService buildProxy() {
final ClientBuilder clientBuidler = ClientBuilder.newBuilder();
// register components, trust manager, etc.
final WebTarget target = clientBuilder.build().target("http://myservice.example.com");
return WebResourceFactory.newResource(
MyService.class, target, false, ImmutableMultivaluedMap.empty(),
Collections.emptyList(), new Form());
}
我想使用这个代理来调用我的方法,但是我找不到一个方便的方法来创建FormDataContentDisposition
。难道我的最佳选择真的是创建头字符串,然后将其传递给new FormDataContentDisposition(String header)
吗?我能否放宽类型限制以获取更方便的构造函数?在文件上传中,是否有不同的更方便的接口可以使用?我主要在我的接口中包含内容规定,以便在将整个文件保存到磁盘之前拒绝过大的文件。