Gists
This is a sample script for uploading local file to Google Drive without the authorization using HTML form. A selected file in your local PC using HTML form is uploaded to Google Drive and saved to Google Drive.
When you use this, at first, please deploy Web Apps. The script is doPost() of following scripts.
Script : Google Apps Script
function doPost(e) {
var data = Utilities.base64Decode(e.parameters.data);
var blob = Utilities.newBlob(data, e.parameters.mimetype, e.parameters.filename);
DriveApp.createFile(blob);
var output = HtmlService.createHtmlOutput("<b>Done!</b>");
output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
return output;
// return ContentService.createTextOutput("Done.") <--- Here, an error occurred.
}
Flow :
- Retrieve data, filename and mimetype as
e.parameters.data, e.parameters.filename and e.parameters.mimetype, respectively.
- Decode the data using
Utilities.base64Decode().
- Create blob using
Utilities.newBlob().
- Create the file in the root folder of Google Drive.
Script : HTML
https://script.google.com/macros/s/#####/exec is the URL obtained when the Web Apps was deployed. Please replace it to your Web Apps URL. You can open this HTML for the browser of your local PC.