I have variables which contain binary image data, mime type and file name. I want to upload the binary data to Google Drive. Are there any ways to upload this in python?
1 Answer
Upload is done in two parts first you upload the metadata, name , description .. then you upload a file stream containing the file data itself
file_metadata = {'name': 'photo.jpg'}
media = MediaFileUpload('files/photo.jpg', mimetype='image/jpeg')
file = drive_service.files().create(body=file_metadata,
media_body=media,
fields='id').execute()
print 'File ID: %s' % file.get('id')
2 Comments
yuki ueda
Thanks. I want to upload the binary data directly, not save it to a file temporary. Can I do this?
Linda Lawton - DaImTo
you are limited to what the MediaFileUpload method supports