我一直在尝试了解如何使用带有 Spring 的 RoboSpice 将文件上传到我的服务器,但我找不到有效的示例。从我确实找到的一个示例中,我构建了:
class UploadJsonRequest extends SpringAndroidSpiceRequest<APIResponseUpload> {
public UploadJsonRequest() {
super( APIResponseUpload.class );
}
@Override
public APIResponseUpload loadDataFromNetwork() throws Exception {
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
for(org.calflora.observer.model.Attachment a : o.attachments){
parts.add(a.name, new FileSystemResource(a.localPath));
}
//parts.add("record", base);
return getRestTemplate().postForObject(URI, parts, APIResponseUpload.class);
}
}
return new UploadJsonRequest();
但是,这给了我错误:
Caused by: org.springframework.web.client.HttpClientErrorException: 404 err: org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/json;charset=UTF-8
好的,所以这似乎表明我需要做一些额外的事情来表明数据应该使用 multipart/form-data 传输。如果这是正确的,这是如何完成的?如果这不正确,那么规范的方法是什么,因为这显然是一种常见的需求?