我想为我的上传组件创建一个暂停和恢复系统。到目前为止,我能够直接和连续上传视频到ym远程服务器与以下代码:
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();
}
我怎么能暂停上传,保存进度。做任何我想做的事情(比如杀死应用程序),然后当我重新启动它时,恢复它并继续上传丢失的部分?
感谢您的宝贵帮助。
我终于找到了一种方法来实现这一点,感谢Github的Kienco
。
下面是他的代码链接:https://github.com/kienco/android-simpl3r