1. You can use any Drive API method in Apps Script by enabling the Advanced Drive Service
The syntax would be
Drive.Files.insert(resource, mediaData, optionalArgs)
2. You can perform an Url fetch request
Whereby the syntax is
UrlFetchApp.fetch(url, options);
and the url and options can be deduced from the method description.
UPDATE
A sample how to create a file in the application folder with url fetch:
Code.gs
function uploadToSharedDrive(){
var url = "https://www.googleapis.com/upload/drive/v3/files?supportsTeamDrives=true&uploadType=resumable";
var blob = Utilities.newBlob('This is the content!');
var metaData = {
'name' :'config.json',
'parents' :["appDataFolder"]
}
params = {
headers: {
Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
},
contentType: 'application/json',
method: 'post',
payload: JSON.stringify(metaData),
}
var response = UrlFetchApp.fetch(url, params);
var data = blob.getBytes();
var params2 = {
method: "put",
payload: data,
muteHttpExceptions: true,
};
location = response.getHeaders().Location;
var response = UrlFetchApp.fetch(location, params2);
Logger.log(response.getContentText())
}
For this code to work correctly, you need to edit the manifest and provide the necessary scopes.
manifest.js:
{
...
"oauthScopes": ["https://www.googleapis.com/auth/drive.appdata", "https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/script.external_request"]
...
}
Keep in mind that the file you create will not be accessible outside of the App - this is intended behavior.