2013-06-24 38 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

感謝您的幫助... –

相關問題