Reputation: 111
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
Reputation: 31310
You can upload files to your drive with the following HTML, client side JavaScript, and .gs server side JavaScript.
<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>
<script>
window.picUpload = function(frmData) {
//console.log("picUpload ran: " + frmData);
google.script.run.withFailureHandler(onFailure)
.withSuccessHandler(updateOutput)
.uploadPic(frmData)
};
</script>
function uploadPic(argBlobInput) {
var uploadedBlob = argBlobInput["picOneUpload"];
var fldrSssn = DriveApp.getFolderById('Your Folder ID');
fldrSssn.createFile(uploadedBlob );
};
Upvotes: 2
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