gpt4 book ai didi

Android暂停和恢复上传

转载 作者:太空狗 更新时间:2023-10-29 14:15:23 26 4
gpt4 key购买 nike

我想为我的上传组件创建一个暂停和恢复系统。到目前为止,我可以使用以下代码直接连续上传视频到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

关于Android暂停和恢复上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22686844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com