Java Robospice-上传InputStreamResource
我在上传带有Java Robospice-上传InputStreamResource,java,android,spring,Java,Android,Spring,我在上传带有InputStreamResource的图像时遇到了一些困难(我刚刚花了一个下午),以下是我当前的代码: MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFor
InputStreamResource
的图像时遇到了一些困难(我刚刚花了一个下午),以下是我当前的代码:
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, bos);
bos.toByteArray();
ByteArrayInputStream bs = new ByteArrayInputStream(bos.toByteArray());
parts.add("photo", new InputStreamResource(bs));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<MultiValueMap<String, Object>>(parts, headers);
RestTemplate template = getRestTemplate();
template.setErrorHandler(new MyDefaultReponseErrorHandler());
template.getMessageConverters().add(new FormHttpMessageConverter());
return template.postForObject("http://bottlapp.cleverapps.io/api/pic", request, Result.class);
MultiValueMap parts=新链接的MultiValueMap();
ByteArrayOutputStream bos=新建ByteArrayOutputStream();
compress(CompressFormat.PNG,0,bos);
bos.toByteArray();
ByteArrayInputStream bs=新的ByteArrayInputStream(bos.toByteArray());
添加(“照片”,新输入流资源(bs));
HttpHeaders=新的HttpHeaders();
headers.setContentType(MediaType.APPLICATION\u FORM\u URLENCODED);
HttpEntity请求=新的HttpEntity(部分、标题);
RestTemplate=getRestTemplate();
setErrorHandler(新的MyDefaultResponseErrorHandler());
template.getMessageConverters().add(新FormHttpMessageConverter());
返回模板。postForObject(“http://bottlapp.cleverapps.io/api/pic“、请求、结果、类);
和生成的跟踪:
03-29 19:00:45.438:E//RequestRunner.java:134(18769):19:00:45.454 Thread-28593请求网络执行期间发生异常:org.springframework.core.io.InputStreamResource无法转换为java.lang.String
03-29 19:00:45.438:E//RequestRunner.java:134(18769):java.lang.ClassCastException:org.springframework.core.io.InputStreamResource无法转换为java.lang.String
有人能帮我吗
谢谢你