2
votes

I am trying to upload files to Google Drive using Google Apps script that also deployed as web app.

In the .html file I got -

<form id="myForm" action='#' method='post' enctype="multipart/form-data" >

    <input type="file" name="filesToUpload[]" id="filesToUpload" multiple="" />

    <input type="submit" value="Upload File" 
           onclick="this.value='Uploading..';
           google.script.run.uploadFiles(this.parentNode)" id="upload-button">

In the .gs file I got -

function uploadFiles(form) {
var file = form['filesToUpload[]'];

I have deployed web app with this code(not only this code of-course).

Each time i upload more then one file in the web app, the variable - 'file' contain only the first file i had uploaded. and not all the files. In other words the fileUpload objects contain each time I have tried the fileUpload-dictionary contain only one file.

fileUpload class - https://developers.google.com/apps-script/reference/ui/file-upload

I read a lot of documentation and I begun to think that it's impossible to upload multiple files using Google apps script(while choosing multiple files in one input of course).

Anyone knows something about it?

Thanks in advance!

1

1 Answers

2
votes

I tried a few things, and I agree that it's impossible. There is a deprecated API method getAllBlobs(), but even that returns a single-element array with just the first file, even when I select multiple files.

On the client-side, the sandbox mode (in which the script runs) seems to prevent fileInput.files property from working: it's always undefined.

Together with a complete lack of documentation on this, it makes for a convincing conclusion that as of May 2015, Google Scripts does not allow multiple file uploads.