How can I upload a local CSV file to Google Drive using the Drive API v2 so that the uploaded file is in the native Google Spreadsheet format. Preferably in Python, but a raw HTTP request will suffice.
What I tried:
-
request body content-type: ‘application/vnd.google-apps.spreadsheet’, media_body content-type: ‘text/csv’. –> 401 Bad Request
-
request body content-type: ‘application/vnd.google-apps.spreadsheet’, media_body content-type: ‘application/vnd.google-apps.spreadsheet’. –> 400 Bad Request
-
… (a couple of others such as leaving a property out and similar, usually got 400 or Drive didn’t recognise it as a native spreadsheet)
Your insert request should specify
text/csvas the content-type.The trick to get the file converted is to add the
?convert=truequery parameter to the request url:https://developers.google.com/drive/v2/reference/files/insert