如何使用AndroidAnnotation从Android发送大型文件到服务器?

Pao*_*laG 5 java rest android android-annotations

我需要从Android平板电脑向服务器发送一个大文件.

所以现在我正在使用Android Annotation它,但现在我得到OutOfMemory Exception因为我的文件大于35MB.我搜索过,并且我不明白,如果我使用FileOutputStream连接,我可以避免这种异常.

但是如何使用我的连接获取输出流@Rest AndroidAnnotation Class

这是我的代码:

@Rest(converters = {FormHttpMessageConverter.class, MappingJackson2HttpMessageConverter.class}
/*, interceptors=MyClientHttpRequestInterceptor.class*/)
public interface DbRestClient  extends RestClientErrorHandling{

    void setRootUrl(String rootUrl);

    String getRootUrl();

    void setRestTemplate(RestTemplate restTemplate);

    RestTemplate getRestTemplate();

    @Post("dbSynk/postNew")
    Integer postDb(MultiValueMap file);
}
Run Code Online (Sandbox Code Playgroud)

进入我的@EService:

@RestService DbRestClient dbRestClient;

...

dbRestClient.postDb(file)
Run Code Online (Sandbox Code Playgroud)

你有什么想法吗?

Ita*_*tto 0

使用@PartFormHttpMessageConverter.

常用的是MappingJackson2HttpMessageConverter将整个文件加载到内存中,同时将文件转换为 JSON。使用FormHttpMessageConverter它将流式传输文件内容而不是将其加载到内存中。