Reputation: 3
i need a little help. Im not a programmer.
I looking for a google script for multiple upload. I found this free sharing script around the web : https://script.google.com/d/1x3p9ZAv-SafEK06r_Vr7fVuUNtEfBg1SGhmSYWjQ0kuPTk-y55a7Nink/edit?usp=sharing
i dont know how to edit it. I really not a programmer. I want to make 2 'choose file' in once upload.
This the original form
<form id="myForm" align="center">
<input type="text" name="myName" placeholder="Your name..">
<input type="file" name="myFile">
<input type="submit" value="Upload File"
onclick="this.value='Uploading..';
google.script.run.withSuccessHandler(fileUploaded)
.uploadFiles(this.parentNode);
return false;">
</form>
What i want something like this,
<form id="myForm" align="center">
<input type="text" name="myName" placeholder="Your name..">
<input type="file" name="myFile">
<input type="file" name="myFile"> <--THIS IS MY NEED, Pls don't laugh
<input type="submit" value="Upload File"
onclick="this.value='Uploading..';
google.script.run.withSuccessHandler(fileUploaded)
.uploadFiles(this.parentNode);
return false;">
</form>
Thanks in advance. Cheers Wan Heri
Upvotes: 0
Views: 1314
Reputation: 51
I came up with a related solution to this problem. Using the Google Drive V3 Api, you can upload a file a few different ways. The accepted answer uses the api directly to upload a blob. Based on my experiments it appears that this method only supports 50MB files. Uploading larger files requires the resumable upload method.
I've created an example form that can create folders, upload large files, and upload those files sequentially. I've created a git hub here: https://github.com/CharlesPlucker/drive-multi-upload/
The main gist includes a few different parts. At it's simplest, you'll need your input to have the multiple
attribute. And you'll want to iterate over the files of that input. Something like this:
var files = [...$('#files')[0].files]; // convert from FileList to array
files.forEach(file => { uploadfile(file); });
Upvotes: 1
Reputation: 13469
Based from this thread, as of right now you have to use a work around to work with multiple files. The multiple attribute only works in IFRAME mode, but file inputs are broken in IFRAME mode.
Here's a sample code for multi-file uploading. Limitations are files must be under 10 MB.
function doGet() {
return HtmlService.createHtmlOutputFromFile('index').setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function saveFile(data,name,folderId) {
var contentType = data.substring(5,data.indexOf(';'));
var file = Utilities.newBlob(Utilities.base64Decode(data.substr(data.indexOf('base64,')+7)), contentType, name);
DriveApp.getFolderById(folderId).createFile(file);
}
Additional references:
Upvotes: 0