Reputation: 8702
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.
Upvotes: 3
Views: 4020
Reputation: 8702
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
Upvotes: 1