Pregunta

How can a file be retrieved from a users drive with Google Apps Script? I've tried:

var fetchURL = 'file:///C://Users//Gigabyte//Pictures//file_name.JPG';
var image = UrlFetchApp.fetch(fetchURL).getBlob();

I've tried using escape characters instead of slashes.

'file:%2F%2F%2FC:%2FUsers%2FGigabyte%2FPictures%2Ffile_name.JPG'

I've tried different variations of back and forward slashes. No luck so far.

Or maybe I'm going about this in the wrong way. Maybe I need to get the file blob some other way?

I did find information on how to get a file from the users drive, into the the website: Stackoverflow Understanding

But Caja does seem to strip out or block a new blob being defined.

I found this code at this site: HTML5 Rocks

// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
  alert('Great success! All the File APIs are supported.');
} else {
  alert('The File APIs are not fully supported in this browser.');
}

When I run that code from Notepad++ in Chrome, it checks out fine. When I run that code inside Google Apps Script in Chrome, something goes wrong. So, . . . obviously there is a way to upload files. It happens all the time. But I can't do it through the HTML service in Google Apps Script. I can trigger a Google Apps Script UI, that will upload a file from the users computer to my Google drive. And I guess that is my only option. I don't know of a way to embed a UI inside of HTML page.

¿Fue útil?

Solución 2

impossible.your gas code is running on google servers not your browser/computer. Your only hope is to do it with htmlService client-side javascript but i doubt the html5 features you might need (i doubt one exists to read a file path) will probably not work due to 'caja' restrictions. If its always an image and you can get it to load on the browser you could also use canvas to capture the data url but again i doubt it can be done from htmlService

Otros consejos

For the sake of anyone trying to find a way to have a user of your Apps Script be able to upload a file from their computer to your Google Drive, here is a Stack Overflow explanation on how to do it.

File Upload with HTML Service

I had thought that there wasn't any way to upload a file with HTML Service, but there is. I spent a lot of time struggling with the UI Service createFileUpload() and all that was a waste of time.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top