使用apache wink客户端上传multipart / form-data文件

时间:2015-05-20 00:17:56

标签: java rest registration multipartform-data apache-wink

目前尚不存在JAX-RS实体提供程序。我尝试上传文件时出现异常..如何注册任何错过的提供商?

使用Apache Wink客户端上传文件的最佳方法是什么,媒体类型是multipart / form-data。

    /* BufferedOutMultiPart requestEntity = new BufferedOutMultiPart();
    requestEntity.setBoundary("Simple-boundary-weqiftugcs");
    OutPart outPart = new OutPart();
    outPart.setBody(file);
    outPart.setContentType(MediaType.MULTIPART_FORM_DATA);
    outPart.addHeader("Content-Transfer-Encoding", "binary");
    outPart.addHeader("Content-Disposition", "form-data; name=\"uploadedFile\";");
    requestEntity.addPart(outPart); */

    MultipartEntity multiPartEntity = new MultipartEntity();
    FileBody fileBody = new FileBody(file);
    multiPartEntity.addPart("uploadFile", fileBody);

    ClientConfig clientConfig = new ClientConfig();
    RestClient restClient = new RestClient(clientConfig);

    Resource restResource = restClient.resource(serviceURL);
    restResource.accept("*/*");
    restResource.contentType(MediaType.MULTIPART_FORM_DATA);
    restResource.post(multiPartEntity);

线程中的异常" main"

  

org.apache.wink.client.ClientRuntimeException:了java.lang.RuntimeException:   了java.lang.RuntimeException:       找不到类org.apache.http.entity.mime.MultipartEntity的javax.ws.rs.ext.MessageBodyWriter实现       type和multipart / form-data媒体类型。验证所有实体提供程序是否正确       注册。添加自定义javax.ws.rs.ext.MessageBodyWriter提供程序来处理类型和       媒体类型,如果JAX-RS实体提供程序当前不存在。

0 个答案:

没有答案