Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带SpringAndroidSpiceRequest的Robospice上载文件_Android_Spring_Robospice - Fatal编程技术网

带SpringAndroidSpiceRequest的Robospice上载文件

带SpringAndroidSpiceRequest的Robospice上载文件,android,spring,robospice,Android,Spring,Robospice,我在机器人世界工作。现在我想上传文件。 我使用SpringAndroidSpiceService编写了自己的请求,如下所示: public class UploadFileRequest extends SpringAndroidSpiceRequest<String>{ private static final String TAG = "UploadFileRequest"; private UploadRequestModel requestModel; private Str

我在机器人世界工作。现在我想上传文件。 我使用SpringAndroidSpiceService编写了自己的请求,如下所示:

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);

}

}
公共类UploadFileRequest扩展了SpringAndroidSpiceRequest{
私有静态最终字符串TAG=“UploadFileRequest”;
私有上传请求模型;
私有字符串链接;
公共UploadFileRequest(UploadRequestModel模型,字符串链接){
super(String.class);
请求模型=模型;
this.link=link;
}
@凌驾
公共字符串loadDataFromNetwork()引发异常{
MultiValueMap parts=新链接的MultiValueMap();
add(“file1”,新的FileSystemResource(requestModel.getFile1());
add(“file2”,新的FileSystemResource(requestModel.getFile1());
HttpHeaders=新的HttpHeaders();
HttpEntity请求=
新的HttpEntity(部件、标题);
返回getRestTemplate().postForObject(链接、请求、字符串、类);
}
}
我现在可以发送文件了。但我面临一个问题。 在文件发送之后。我在磁盘上的文件几乎被删除了。它的大小是零。 你知道为什么吗?我怎样才能解决这个问题?
非常感谢您的帮助。

我是RS的作者之一。您面临的问题与RS没有直接关系,而是与Spring Android有关。我建议你写信给他们的论坛以获得答案。对不起,我们不能告诉你更多了

圣菲

        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;
这是我的密码,
在我遇到同样的问题之前,它工作不正常。您可以尝试此消息
在此处输入代码
转换器,这将有助于

在上述代码中,您引用了“UploadRequestModel”类型的对象。我找不到关于这个物体的任何文档-你能给我一些见解吗?啊。UploadRequestModel只是一个POJO类。我用它来包含文件路径。谢谢,我解决了我的问题-与没有找到消息转换器有关。按照restTemplate.getMessageConverters().add(新FormHttpMessageConverter()),虽然根据文件,这是没有必要的,因为它是。