微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PyDrive上传速度太慢

如何解决PyDrive上传速度太慢

我正在使用 PyDrive 将文件从我的 RPi 上传到我的 Google Drive 中的特定文件夹。它工作成功,但速度非常慢。对于只有 40kB 的 .npy 文件(二进制 numpy 文件),上传速度约为 2 秒。当我尝试上传 2MB 的其他文件 (.pptx) 时,上传速度约为 5 秒。我也在我的 Mac 上试过这个,它的上传速度相同。

有没有更好的方法来做到这一点?我需要不到一秒的上传速度,因为我每秒都在收集数据。代码如下:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
import os
import time

credentials = '/***/pydrive_credentials.txt'
directory = '/***/remote_dir'
gauth = GoogleAuth()
gauth.LoadCredentialsFile(credentials)
# gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)


# get id of designated folder in Google Drive 
folder = drive.ListFile({'q': "title = 'sample pydrive folder' and trashed=false"}).GetList()[0]

for filename in os.listdir(directory):

    f = drive.CreateFile({'title': filename,'parents': [{'id': folder['id']}]})
    # f = drive.CreateFile()
    filepath = os.path.join(directory,filename)
    f.SetContentFile(filepath)
    start = time.time()
    f.Upload()
    end = time.time()
    print(end-start)

    # delete file after upload
    # os.remove(filepath)
    
    # to ensure no memory leakage
    f = None
    filepath = None

    print("Uploaded: {}".format(filename))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。