RestEasy客户端框架文件上传 [英] RestEasy client framework file upload

查看:539
本文介绍了RestEasy客户端框架文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何使用以下两个接口签名来创建RestEasy客户端调用来上传文件?我没有找到任何信息。我知道如何使用HttpClient,但我想使用客户端代理,以保持一致。


@Path(/ upload)
@Consumes(multipart / form-data)
public void uploadFile(MultipartFormDataInput input);
$ b @POST
@Path(/ upload2)
@Consumes(multipart / form-data)
public void uploadFile2(@MultipartForm FileUploadForm form) ;

任何帮助将不胜感激,
Fredrik



 <$ 

c $ c> ResteasyClient client = new ResteasyClientBuilder()。build();

ResteasyWebTarget target = client.target(http://.../upload);

MultipartFormDataOutput mdo = new MultipartFormDataOutput();
mdo.addFormData(file,new FileInputStream(new File(.... thermo.wav)),
MediaType.APPLICATION_OCTET_STREAM_TYPE);
GenericEntity< MultipartFormDataOutput> entity = new GenericEntity< MultipartFormDataOutput>(mdo){};

响应r = target.request()。post(Entity.entity(entity,MediaType.MULTIPART_FORM_DATA_TYPE));


Does anyone know how to create the RestEasy client side calls to upload a file using the following two interface signatures? I'm not finding any information at all. I know how to do it using the HttpClient but I'd like to use the client proxy to keep it consistent.

@POST
@Path("/upload")
@Consumes("multipart/form-data")
public void uploadFile(MultipartFormDataInput input);

@POST
@Path("/upload2")
@Consumes("multipart/form-data")
public void uploadFile2(@MultipartForm FileUploadForm form);

Any help would be appreciated, Fredrik

解决方案

With RESTEasy 3.0.X a file upload via MultipartFormData could look like this:

ResteasyClient client = new ResteasyClientBuilder().build();

ResteasyWebTarget target = client.target("http://.../upload");

MultipartFormDataOutput mdo = new MultipartFormDataOutput();
mdo.addFormData("file", new FileInputStream(new File("....thermo.wav")),
    MediaType.APPLICATION_OCTET_STREAM_TYPE);
GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(mdo) {};

Response r = target.request().post( Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));

这篇关于RestEasy客户端框架文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆