Upload generic binary files to GDrive using API

Viewed 285

I would like to upload generic binary files (to be specific .root files, output of ROOT by CERN) to Google Drive using Python 3.6 and Google Drive API v3. If I try my usual code:

FILES = ((filename, None) for filename in filelist)
for filename, mimeType in FILES:
    metadata = {'name': filename}
    if mimeType:
        metadata['mimeType'] = mimeType
    res = DRIVE.files().create(
        body = metadata, media_body = filename).execute()

I get the following error:

raise UnknownFileType(media_filename)
googleapiclient.errors.UnknownFileType

I guess it depends from the fact that root files are unknown to GDrive. Is there any way to upload them nonetheless (or any other "custom" binary file, if that matters)?

1 Answers

The most extensive file extension mime type list that i am aware of for google drive can be found here. MimeType.cs

I dont think you are going to be able to just make up your own file extension and mime type then upload it. It needs to be one of the ones on the list or google drive doesn't know what to do with it.

Have you considered just ziping your file and then using

{".zip", "application/x-zip-compressed"},

Related