I want to create a file with content using Google Drive API v3. I have authenticated via OAuth and have the Drive API loaded. Statements like the following work (but produce a file without content):
gapi.client.drive.files.create({
"name": "settings",
}).execute();
Unfortunately I cannot figure out how to create a file that has a content. I cannot find a JavaScript example using Drive API v3. Are there some special parameters that I need to pass?
For simplicity, assume that I have a String like '{"name":"test"}' that is in JSON format that should be the content of the created file.
here is the solution with
gapi.client.drive
,you'll need to connect/authorise with either of the following scopes
EDIT: it is possible to create google files (doc, sheets and so on) by changing the
mimeType
fromapplication/vnd.google-apps.folder
to one of the supported google mime types. HOWEVER, as of now it not possible to upload any content into created files.To upload files, use the solution provided by @Geminus. Note you can upload a text file or a csv file and set its content type to google doc or google sheets respectively, and google will attempt to convert it. I have tested this for text -> doc and it works.
this works fine usin v3:
Source: https://gist.github.com/mkaminsky11/8624150
Unfortunately, I have not found an answer using only the google drive api, instead I followed Gerardo's comment and used the google request api. Below is a function that uploads a file to google drive.