'What Is the Correct Mimetype (in and out) for a .Py File for Google Drive?

I have a script that uploads files to Google Drive. I want to upload python files. I can do it manually and have it keep the file as .py correctly (and it's previewable), but no matter what mimetypes I try, I can't get my program to upload it correctly. It can upload the file as a .txt or as something GDrive can't recognize, but not as a .py file. I can't find an explicit mimetype for it (I found a reference for text/x-script.python but it doesn't work as an out mimetype).

Does anyone know how to correctly upload a .py file to Google Drive using REST?



Solution 1:[1]

In your situation, I think that text/x-python can be used for uploading the python scripts as the mimeType. For example, the curl sample is as follows.

curl -H "Authorization: Bearer [access token]" \
  -F "metadata={name: 'sampleFile.py', mimeType: 'text/x-python'};type=application/json;charset=UTF-8" \
  -F "[email protected]" \
  "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"

Reference:

Solution 2:[2]

Also this is a valid Python mimetype: text/x-script.python

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tanaike
Solution 2 Jankelele