AsynchronousResumableUploadForGoogleDrive icon indicating copy to clipboard operation
AsynchronousResumableUploadForGoogleDrive copied to clipboard

How can I push the uploads into a unique folder?

Open NoSubstitute opened this issue 4 years ago • 3 comments

I turned this into a simple/pure webapp by replacing this code, and it works great.

`function doGet() { return HtmlService.createHtmlOutputFromFile("index.html"); }

// function main() { // var html = HtmlService.createHtmlOutputFromFile("index"); // SpreadsheetApp.getUi().showSidebar(html); // }`

But, since it uploads the files straight into the root of MyDrive, it can easily be cluttered, and instead I would like each upload to be sent to a specific dated folder inside a base folder. Something like this: /FileUploads/2021-07-01T10:03:15/

So if I upload 10 files in one upload, I want them all there in one dated folder, and the next uplöoad is collected in a new unique dated folder.

How can that be achieved?

I assume most people would like to set the base folder as a constant in the script, since we may all have different names of our base folder, and maybe not everyone would want a dated subfolder, so maybe a "const datedFolder = true" or something would be a good idea?

NoSubstitute avatar Jul 01 '21 08:07 NoSubstitute

Simply include folderID in resource variable inside ResumableUploadForGoogleDrive function:

const resource = {
         fileName: f.fileName,
         fileSize: f.fileSize,
         fileType: f.fileType,
         fileBuffer: f.result,
         accessToken: accessToken,
         folderId: "{yourFolderId}" //include this line
       };

bbscout avatar Jan 04 '22 13:01 bbscout

That worked like a charm, thank you!

Took me one try to realise I should only put the folderId between the "quotes" and not the {also}. I'm learning. :-)

Now if I only knew how to add a new dated/timed sub-folder to the specified folderId, I'd be all set! :-)

NoSubstitute avatar Jan 04 '22 13:01 NoSubstitute

Simply include folderID in resource variable inside ResumableUploadForGoogleDrive function:

const resource = {
         fileName: f.fileName,
         fileSize: f.fileSize,
         fileType: f.fileType,
         fileBuffer: f.result,
         accessToken: accessToken,
         folderId: "{yourFolderId}" //include this line
       };

Hi. Please, help. How can I use folderId from google sheets cell? I use var folderId= sheet.getRange('B5').getValue(); but if I change folderId: folderId- it doesnt work...

DarckGraf avatar Feb 03 '24 15:02 DarckGraf