Google Apps Script / Niotron Guide · February 28, 2021 0

How to use Google Drive Component Of Niotorn Builder.

Here in this blog, I’m going to explain to you How to use the nation’s Google Drive Component. But before I start, do you know you can upload any file like text, docs, pdf, Xls, etc also media files like video, audio, images, gifs, etc to your google drive very easily. So let’s get started 😀

I have made a very simple project using few components of builder

  • 1 Image Component, to display image which we’ll pick/select from gallery.
  • 1 Image Picker, to pick an image from the gallery.
  • Google Drive component
  • 1 Button to trigger upload media block of the google drive component
  • And a label to show logs/actions
Google drive component in niotron

Now we need 3 things for Google Drive Component to upload data,

  • File Name
  • Folder ID
  • Server URL

File Name

I have made a procedure using which you can get file name ‘which is picked’ from gallery/path.

Let’s get the Folder ID now

Go to drive.google.com and create a new folder. [Note: If you already have a folder then you can use that too ]. Now go to that folder. Once you are in, copy the folder id from the address bar of your browser. Also, make sure to change the folder permission. Anyone on the internet with this link can viewChangeCopy link

Now let’s get the Server URL

Go to script.google.com and create a new project. Once the project is loaded in the new tab, Rename the project to “Niotron GoogleDrive” or anything you like too. Now clear all default code from the board and paste this below-given code.

function doPost(e) {
    var data = Utilities.base64Decode(e.parameters.data);
    var blob = Utilities.newBlob(data, e.parameters.mimetype, e.parameters.filename);
    var file = DriveApp.getFolderById(e.parameters.folderid).createFile(blob);
        file.setSharing(DriveApp.Access.ANYONE_WITH_LINK,DriveApp.Permission.VIEW);
    var fileID =file.getId();
    return ContentService.createTextOutput(fileID);
}

Note this code was originally written by TIMAI2 but I have modified it a bit to get compatible with the Google Drive component of the Niotron builder.

Now simply deploy this project as a web app. Click here if you don’t know how to deploy. Once you have done the deployment you’ll have your Server URL. Simply paste all these details (Folder ID & Server URL only ) to the Google Drive components property.

Now let’s write some blocks to upload files on our google drive.

Note that, I have used labels only to display current actions you can use notifiers if you want. Click here to download this sample project/aia file and give it a try. Also if you have any query feel free to ask in the comment below.