Upload a file of 0 bytes fails
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()
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
Alternatively #88 is similar and there is a fix on a dev branch!
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