PyDrive icon indicating copy to clipboard operation
PyDrive copied to clipboard

Upload a file of 0 bytes fails

Open kabads opened this issue 6 years ago • 3 comments

If I try and upload a file with 0 bytes (i.e. empty) then I get a 400 return. However, if I put some content in that file, the file uploads happily. Is this the expected behaviour? I thought it would be to upload the file regardless.

The file is a regular test.txt file using the following code:

file.driveCreateFile()
file.SetContentFile('test.txt')
file.Upload()

kabads avatar Jan 24 '18 10:01 kabads

No need to set any content if it's going to be empty:

from pydrive import auth, drive
#authorize however you want
gauth = auth.GoogleAuth().LocalWebserverAuth()

#create your drive object
drive = drive.GoogleDrive(gauth)
#Create the file
file1 = drive.CreateFile({'title': 'Hello.txt'})
# Upload the file to your drive
file1.Upload() 

Checkout the docs on file management

keliomer avatar Jan 29 '18 22:01 keliomer

Alternatively #88 is similar and there is a fix on a dev branch!

keliomer avatar Feb 02 '18 19:02 keliomer

Seems to be fixed in https://github.com/googleapis/google-api-python-client/issues/638 (google-api-python-client >= 1.12.25) https://github.com/googleworkspace/PyDrive/blob/871f7d644dd5df1c6190f7c7eebbab9721ccd4f4/setup.py#L16

efiop avatar Oct 22 '20 15:10 efiop