Elliott Shafii
Elliott Shafii

Reputation: 111

How to use Google Drive File Picker with Apps Script HTML Service

Does anyone have any samples of using Google Drive FilePicker with Apps Script HTML Service. Is it even possible?

I'd like to use it to select files or upload files from Drive using AppsScript HTML Service.

Upvotes: 3

Views: 3723

Answers (2)

Alan Wells
Alan Wells

Reputation: 31310

You can upload files to your drive with the following HTML, client side JavaScript, and .gs server side JavaScript.

HTML

<form class='frmUpload'>
  <input name="picOneUpload" type="file" accept="image/*" onchange="picUpload(this.parentNode, 'a')" ><label id='lblPicLoadA'>Pick a Picture To Upload!</label>
</form>

JavaScript - in HTML Script tag

<script>
  window.picUpload = function(frmData) {
  //console.log("picUpload ran: " + frmData);
   
  google.script.run.withFailureHandler(onFailure)
    .withSuccessHandler(updateOutput)
    .uploadPic(frmData)
  };
</script>

Code.gs

function uploadPic(argBlobInput) {
  var uploadedBlob = argBlobInput["picOneUpload"];
  var fldrSssn = DriveApp.getFolderById('Your Folder ID');
  fldrSssn.createFile(uploadedBlob );
};

Upvotes: 2

Eric Koleda
Eric Koleda

Reputation: 12671

Unfortunately it isn't possible to use it in HtmlService, due to Caja restrictions. We're working on enabling it, but it may take some time.

Edit As of March 2014 this is now possible. See this page for sample code.

Upvotes: 3

Related Questions