繁体   English   中英

使用Google App Engine Python将大文件上传到Google云端硬盘时出现400错误请求

[英]400 Bad Request while Uploading large file to Google Drive with Google App Engine Python

我正在创建一个Google App Engine应用程序,我想在其中将文件上传到我的Google云端硬盘文件夹中。

为此,我正在使用Google API Python客户端库。 https://code.google.com/p/google-api-python-client/

我正在从库中使用MediaIoBaseUpload函数,因为我正在从一个Form获取文件内容。 我正在使用断点续传。

当我上传大约15 MB的较小大小的文件时,它可以正常工作,但是大于15 MB的文件在最后一个块中出现错误400 Bad Request。

之前的所有块均正常运行,但最后一个块返回错误。

我正在尝试上传一个zip文件(约46 MB)。

这是我的代码:

fh = io.BytesIO(self.fileContent)
media = MediaIoBaseUpload(fh, "application/zip", 1024 * 1024, resumable=True)
http = httplib2.Http()
if credentials.invalid is True:
    credentials.refresh(http)
else:
    http = credentials.authorize(http)

drive_service = build('drive', 'v2', http=http)

body = {
    'title': self.fileName,
    'description': "",
    "parents": [{
                    "kind": "drive#fileLink",
                    "id": self.folderId
                }],
    'mimeType': fileMimeType
  }

response = drive_service.files().insert(body=body, media_body=media).execute()

不要为父级设置kind属性。 请使用以下列表:

"parents": [{ "id": self.folderId }]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM