Android pause and resume upload

社会主义新天地 提交于 2021-02-07 03:57:49

问题


I'd like to create a pause and resume system for my uploading component. So far I'm able to directly and continuously upload a video to ym remote server with the following code:

private void uploadVideo(String videoPath) throws Exception
{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(SEVER_ENDPOINT);

    FileBody filebodyVideo = new FileBody(new File(videoPath));
    StringBody title = new StringBody("Filename: " + videoPath);
    StringBody description = new StringBody("Short description");

    MultipartEntity reqEntity = new MultipartEntity();
    reqEntity.addPart("videoFile", filebodyVideo);
    reqEntity.addPart("title", title);
    reqEntity.addPart("description", description);
    httppost.setEntity(reqEntity);

    if (DEBUG) Log.d(TAG, "executing request " + httppost.getRequestLine());
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    if (DEBUG) Log.d(TAG, response.getStatusLine());
    if (resEntity != null)
    {
        if (DEBUG) Log.d(TAG, EntityUtils.toString(resEntity));
        resEntity.consumeContent();
    }
    httpclient.getConnectionManager().shutdown();
}

How could I pause the upload, save the progress. Do whatever I want (Like killing the app) and then when I restart it, resume it and continue to upload the missing part ?

Tahnks for your precious help.


回答1:


I've finally found a way to achieve to do that, thanlks to Kienco from Github.

Here is a link to his code: https://github.com/kienco/android-simpl3r



来源:https://stackoverflow.com/questions/22686844/android-pause-and-resume-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!