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 (将#修改为@)