Zero byte file upload to Drive v3 using Python

170 views
Skip to first unread message

Steve Hubbard

unread,
Feb 16, 2016, 10:58:43 AM2/16/16
to Google API Python Client
I am able to use apiclient.http.MediaFileUpload in combination with service.files().create() to upload files to my drive in Python. However, if the file I am trying to create is zero bytes I get a HttpError 400 when requesting https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&alt=json returned "Bad Request" response.

I can't find anything in the documentation (or anywhere on the web in general) that mentions zero byte file creation through the API. Am I missing something? I am able to drag the zero byte file into Google Drive through the webpage and it uploads ok.

Here is a stripped down chunk of my code:
mimeType = mime.from_file(filePath)
media = apiclient.http.MediaFileUpload(
    filePath,
    mimetype=mimeType,
    chunksize=4194304,
    resumable=True
)

bodyDict = {
    'name': fileName,
    'parents': [fileParentID]
}

request = service.files().create(
    media_body=media,
    body=bodyDict
)

status, response = request.next_chunk()

Thanks
Reply all
Reply to author
Forward
0 new messages