2013-06-24 32 views
2

我正在创建一个Google App Engine应用程序,我要将文件上传到我的Google云端硬盘文件夹。400使用Google App Engine将大文件上传到Google云端硬盘时的错误请求蟒蛇Python

为此,我使用Google API Python Client Library。 https://code.google.com/p/google-api-python-client/

我从库中使用MediaIoBaseUpload函数,因为我从一个表单获取文件内容。我正在使用可恢复的上传。

当我上传15 MB左右的较小文件的文件时,它工作正常,但大于15 MB的文件我在上一个块中收到错误400错误请求。

所有以前的块都可以正常工作,但是最后一块返回错误。

我想上传一个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() 

在此先感谢...

+0

父母的种类是驱动器#parentReference,而不是驱动器#fileLink。 – peter

回答

1

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

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

感谢您的帮助... –

相关问题