簡體   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