Upload a file to a Google Web Apps with doPost

2019-05-21 18:22发布

问题:

I'm trying to upload a file to a Google Web App with doPost(e), as shown below.

function doPost(e) {
    var blob = e.parameter.myFile;
    DriveApp.createFile(blob);
}

A file is then POSTed to the web app at the client side. The POST has been proved to work correctly with on my own web server.

However the blob variable, in the code above, is not actually a Blob type, it is a string type. How does Google script engine prepare parameter e? Is there a way to make this work?

回答1:

I got the same problem here. An workaround you can do is convert your file to a Base64 string using FileReader(), upload it, and convert it back on server-side before sending it to your Google Drive.

Here's how to encode your file and decode it server-side using Utilities API