我在尝试上传文件时收到该错误。我有一个代码在下面,我收到No MessageBodyWriter for body part of type 'java.io. File' and media type 'application/octet-stream'
异常。我昨天试图解决这个问题,但没有成功。Jersey没有MessageBodyWriter类型为“java.io.File”的身体部分
File file = new File(path);
ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
Client client = Client.create(cc);
WebResource webResource = client.resource(Constants.URL).path("images")
.path("create");;
FormDataMultiPart fdmp = new FormDataMultiPart();
fdmp.bodyPart(new FileDataBodyPart("filename", file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
fdmp.bodyPart(new FormDataBodyPart("data", imageData));
ClientResponse response = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, fdmp);
我已经尝试了一些其他版本,但我不断收到该异常。有什么建议? :)
[尝试将文件上传到JAX-RS(球衣)服务器]的可能重复(http://stackoverflow.com/questions/ 5772225 /试图上传一个文件到一个jax-rs-jersey-server) – Perception 2013-02-26 20:25:20