I'm using PyDrive to upload files from my RPi to a specific folder in my Google Drive. It is successfully working, but the speed is terribly slow. For a .npy file (binary numpy file) that is only 40kB, the upload speed is around 2 seconds. When I try uploading a different file (.pptx) that is 2MB, the upload speed is around 5 seconds. I also tried this on my Mac, and it has the same upload speed.
Is there a better way to do this? I need an upload speed that is less than a second since I'm collecting data every second. Here is the code:
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))
question from:
https://stackoverflow.com/questions/65838981/pydrive-upload-speed-is-too-slow 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…