取消Google Drive上传可能吗? [英] Cancel Google Drive upload possible?

查看:178
本文介绍了取消Google Drive上传可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用官方API编写了一个应用程序上传到Google驱动器,这个功能完美无缺。不过,我无法找到取消上传。我在一个ASyncTask中运行它,到目前为止,我已经尝试制作驱动器对象,文件路径,令牌和其他一些变量。我也尝试使令牌失效,但它似乎只是将它从缓存中删除,实际上并没有使服务器端失效。我已经在ASyncTask上调用了cancel,但是如果一旦上传启动就取消了,似乎没有办法阻止它。

I have written an app using the official API to upload to Google drive, this works perfectly. However I can't find anyway to cancel an upload. I'm running it in an ASyncTask, so far I have tried making the drive object, the file path, the token and a few other variables none. I've also tried to invalidate the token however it seems this only removes it from the cache and doesn't actually invalidate it server side. I've called cancel on the ASyncTask however if it is cancelled once the upload has started there seems to be no way to stop it.

我的问题是如果用户启动上传一个100MB的文件没有办法让他们取消它,然后打开和关闭他们的互联网连接,这是不实际的。这是我的上传代码:

My issue is if a user starts uploading a 100mb file there's no way for them to cancel it other then turning their internet connection on and off which isn't practical. This is my upload code:

  java.io.File jFile = new java.io.File(path); //Does not get file just info
                File body = setBody(jFile, mimeType);
                try
                {
                  java.io.File mediaFile = new java.io.File(path);
                  InputStreamContent mediaContent =
                      new InputStreamContent(mimeType,
                          new BufferedInputStream(new FileInputStream(mediaFile)));
                  mediaContent.setLength(mediaFile.length());
                  request = drive.files().insert(body, mediaContent);
                  request.getMediaHttpUploader().setProgressListener(new CustomProgressListener());
                  File file = request.execute();

确实有办法取消上传吗?

Surely there is a way to cancel an upload?

推荐答案

伟大的问题!我提出了取消媒体上传请求的功能请求:

Great question! I filed a feature request for the ability to cancel a media upload request:

https://code.google.com/p/google-api-java-client/issues/detail?id=671

然而,这可能是一个很难实现的功能,它基于该库的当前设计。

However, this may a difficult feature to implement based on the current design of that library.

另一个选项要考虑的是不使用AsyncTask,而是自己实现多线程并中止正在运行的线程。不愉快,但可能是您现在唯一的选择。

Another option to consider is to not use AsyncTask and instead implementing the multi-threading yourself and abort the running Thread. Not pleasant, but may be your only option for doing this now.

这篇关于取消Google Drive上传可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆