问题
I am working with robospice. Now I want to upload file. I used SpringAndroidSpiceService and write my own request like this :
public class UploadFileRequest extends SpringAndroidSpiceRequest<String>{
private static final String TAG = "UploadFileRequest";
private UploadRequestModel requestModel;
private String link;
public UploadFileRequest(UploadRequestModel model, String link) {
super(String.class);
requestModel = model;
this.link = link;
}
@Override
public String loadDataFromNetwork() throws Exception {
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
parts.add("file1", new FileSystemResource(requestModel.getFile1()));
parts.add("file2", new FileSystemResource(requestModel.getFile1()));
HttpHeaders headers = new HttpHeaders();
HttpEntity<MultiValueMap<String, Object>> request =
new HttpEntity<MultiValueMap<String, Object>>(parts, headers);
return getRestTemplate().postForObject(link, request, String.class);
}
}
I can send the files now. But I faced a problem. After the files have sent. My files on disk are almost deleted. It's size is zero. Do you know why ? and how can I resolve it ? Thank you very much for any help.
回答1:
I am on of the authors of RS. The problem you face is not related to RS directly but to Spring Android. I suggest you write to their forum to get an answer. Sorry, but we can't tell you more.
Stéphane
回答2:
this.message.setApi_key(ConfigurationBean.getTab_id());
this.message.setApi_password(ConfigurationBean.getTab_assword());
this.message.setNursery_id(ConfigurationBean.getNursery_id());
url=ConfigurationBean.getNursery_url()+"/api/v1/installation.php";
try {
list=service.getConfiguration(admin, pass);
} catch (Exception e) {
Log.e("request", ""+e.getMessage());
}
// Add the Jackson and String message converters
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
// Make the HTTP POST request, marshaling the request to JSON, and the response to a String
String response = restTemplate.postForObject(url, message, String.class);
return response;
this is my code,
before i was getting the same problem ,not its working fine u can try this message enter code here
converter which will help
来源:https://stackoverflow.com/questions/15769019/robospice-upload-file-with-springandroidspicerequest