HTTP POST和Google Apps脚本文件上传 [英] HTTP POST and Google Apps Script file upload

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

问题描述

请原谅这个问题的重复性,但是经过数小时的搜索后无济于事,我选择向社区提出以下问题:

Forgive the possible duplicity of this question, but after hours of searching to no avail, I've elected to ask the following of the community:

是否可以通过以下方式使用带有HTML和Javascript的以下表单(带有POST或GET请求),使我可以从普通HTML页面中拥有用户,从而能够提交和上传文件通过将表单操作=定向到Google脚本"来访问Google云端硬盘?

Is there any means by which, using the following form with HTML and Javascript (with a POST or GET request) that I might be able to have a user, from a normal HTML page, be able to submit and upload a file to Google Drive by means of having the "form action =" being directed at a Google Script?

我已经能够仅使用指向Google脚本的表单操作就成功地将值写入Google Spreadsheet,该操作包含一个doPost(e),然后捕获e.parameter.[input_field_name_here]并执行计算.

I have been able to successfully write values to a Google Spreadsheet using only a form action directed to a Google Script which holds a single doPost(e) which then grabs the e.parameter.[input_field_name_here] and performs the calculations.

我一直在尝试多种方法,但这只是我所能达到的程度.

I have been toying with a combination of methods, but this is about as far as I've been able to get.

当前HTML:

<form method="post" action="my_google_script_published_as_web_app_url/exec" name="quoteForm" id="quoteForm" target="hidden_iframe"> 
  <input type="file" name = "thefile">
</form> 

Google Apps脚本

function doPost(e) 
   {
   var fileBlob = e.parameter.thefile;
   Logger.log(e);
   Logger.log(fileBlob);
   var doc = DocsList.createFile(fileBlob.getBlob());
   }

我尝试使用以下代码变体,以尝试通过此方法执行上传:

I have attempted the following variations with the code in order to try to perform an upload via this method:

  • enctype="multipart/form-data"添加到表单中以查看是否存在问题.
  • 尝试改为使用"GET"请求.
  • Added the enctype="multipart/form-data" to the form to see if that was an issue.
  • Attempted to use a "GET" request instead.

就可用的实际可用结果而言,我能得到的最接近的错误返回无法将数组转换为BlobSource"和无法在字符串类型上调用.getBlob()"的错误结果.以及"... on type Object".

The closest I have been able to get in terms of an acutal useable result is an error return of "unable to convert Array to BlobSource" and, a further result of "unable to to call .getBlob() on type string" as well as "...on type Object".

这完全有希望吗?我一直在尝试从这里收集信息,以及以下两个问题,这些问题听起来像是与此处,其中后者似乎与我所面临的最接近.

Is there any hope to this at all? I've been trying to glean what I could from here, as well as the following two issues regarding what sounds like bugs related to a method like this here and here with the latter seeming the closest to what I'm facing.

非常感谢您对此事的协助.

Many thanks in advance for any assistance on this matter.

推荐答案

我认为这仍然是残破"的.我不知道它是否打算保留下去.经过一番详尽的尝试和错误之后,我得出结论,尽管可以执行doPost,但是您永远不会得到可用的响应(而且我无法想到这样的情况:您不会在意上载是否成功或不).基本上,您遇到了跨域问题,该问题已在中为您解决了htmlService示例. "get"将永远无法上传.

I think this is still 'broken'. Whether it is intended to remain so, I don't know. After some exhaustive trial and error, I concluded that although it is possible to get a doPost to execute, you are never going to get a usable response (and I can't think of a case where you would not care whether the upload is successful or not). Basically you come up against the cross-domain issue which is solved for you in the htmlService example. 'get' will never work for the upload.

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

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