There are four ways to create a new file:
The documentation for INSERT for the Drive API is found at this link:
Drive API for INSERT
There is a section for Request body. One of the Optional Properties for Insert is parents[]. The brackets [] indicate that a list of parents can be designated. The documentation for parents[] states this:
Collection of parent folders which contain this file. Setting this field will put the file in all of the provided folders. On insert, if no folders are provided, the file will be placed in the default root folder.
So, . . . using Insert in Drive API, . . . . CAN write a new file directly to a subfolder. It's possible.
Now, the nomenclature and syntax for the Google Drive SDK, HTTP request is different than what is inside of Apps Script.
The syntax for invoking the Drive API HTTP Request inside of a .gs
file is one of the following three:
The syntax shown in the list above is from the auto-complete drop down list inside the Apps Script code editor. If you type Drive.Files.
a list of possible methods will appear. I can't find information about the syntax anywhere in the online documentation.
So, where does the parents[] optional property go? Well, it's not a Blob, so we can rule that out. It's either FILE resource
, or OBJECT optionalArgs
. optionalArgs indicates that it's an object, but FILE resource
is actually also an object.
In the examples, the FILE resource
is constructed as key:value pair object.
Uploading Files - Advanced Drive Service - Google Documentation