gpt4 book ai didi

python - 使用 PyDrive 将大文件上传到 Google Drive

转载 作者:太空宇宙 更新时间:2023-11-03 18:03:31 26 4
gpt4 key购买 nike

目前,我正在使用 PyDrive 将备份(.tar 文件)上传到 Google 云端硬盘。

这个库有什么特殊的用途可以将一个巨大的文件上传到 Google Drive(大约 5GB)吗?在Google Drive API文档中,它说我们必须使用断点续传上传? https://developers.google.com/drive/web/manage-uploads

我的问题是,当我尝试发送一个大文件时,脚本执行得非常快,没有任何错误,而且该文件没有出现在 GoogleDrive 中。但是,如果我用一个大约 100mb 的小文件执行此操作,一切都会正常工作......

我的代码如下:

def upload(self, backupFile, backupFileName):

json_data=open(os.path.join(__location__, 'client_secrets.json'))

data = json.load(json_data)

"""Email of the Service Account"""
SERVICE_ACCOUNT_EMAIL = data['client_email']

"""Path to the Service Account's Private Key file"""
SERVICE_ACCOUNT_PKCS12_FILE_PATH = os.path.join(__location__, 'key.p12')

f = file(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
key = f.read()
f.close()

credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL, key,
scope='https://www.googleapis.com/auth/drive', sub='email')
http = httplib2.Http()
credentials.authorize(http)

gauth = GoogleAuth()
gauth.credentials = credentials

drive = GoogleDrive(gauth)

file1 = drive.CreateFile({'title': backupFileName, "parents" : [{"id":"0B7FoN03AUUdZVlNETEtWLS1VTzQ"}]} ) # Create GoogleDriveFile instance with title 'Hello.txt'

file1.SetContentFile(backupFile);
file1.Upload()

当我尝试发送大文件时,没有返回任何错误。 python 脚本只是结束,没有显示任何内容...

最佳答案

某些类型的文件有 100MB 的限制

https://support.google.com/drive/answer/37603?hl=en

Size limits

Documents: 1,024,000 characters, regardless of the number of pages or font size. If using the new version of Drive (with the red "New" button on the left side), uploaded document files that are converted to the Google documents format can’t be larger than 50 MB. If using the classic version of Drive, you can't convert document files that are larger than 10 MB.

Spreadsheets: 400,000 cells, with a maximum of 256 columns per sheet. Uploaded spreadsheet files that are converted to the Google spreadsheets format can’t be larger than 100 MB, and need to be under 400,000 cells and 256 columns per sheet.

More information about spreadsheet size limits All spreadsheet limits mentioned above have been removed in the new version of Google Sheets. The new version of Google Sheets should support 2 million cells of data, though please note that extremely large spreadsheets may have slower performance. Learn more about switching to the new version of Google Sheets. Presentations: Presentations created in Google Slides can be up to 100 MB. Uploaded presentation files that are converted to Google Slides can also be up to 50 MB.

Drawings: We’ve never seen anyone make a drawing that was too big (but that’s not a dare).

Other files: Files that you upload but don’t convert to a Google Docs, Sheets, or Slides format can be up to 5 TB each.

Across Google Drive, Gmail, and Google+ Photos, every user is given 15 GB of free storage space, and can purchase additional storage as well.

关于python - 使用 PyDrive 将大文件上传到 Google Drive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27303439/

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