使用doPost将文件上传到Google Web Apps [英] Upload a file to a Google Web Apps with doPost

查看:89
本文介绍了使用doPost将文件上传到Google Web Apps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我试图用doPost(e)将文件上传到Google Web App,函数doPost(e){
var blob = e.parameter.myFile;
DriveApp.createFile(blob);
}

然后将文件发布到客户端的Web应用程序。 POST已被证明可以在我自己的Web服务器上正常工作。



然而,上面代码中的blob变量实际上并不是Blob类型,它是字符串类型。 Google脚本引擎如何准备参数e?有没有办法使这项工作?

解决方案

我在这里遇到同样的问题。您可以做的解决方法是使用FileReader()将文件转换为Base64字符串,然后将其上传,然后在将其发送到Google Drive之前将其转换回服务器端。



以下是如何编码您的文件和< a href =https://developers.google.com/apps-script/reference/utilities/utilities =nofollow noreferrer>解码服务器端使用实用程序API


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?

解决方案

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

这篇关于使用doPost将文件上传到Google Web Apps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆