【问题标题】:Google script HTML api can´t process file upload fieldGoogle 脚本 HTML api 无法处理文件上传字段
【发布时间】:2013-10-23 22:52:10
【问题描述】:

我正在尝试使用 HTML api 在谷歌脚本中创建一个简单的网络应用程序。

代码.gs

function doGet() {
    return HtmlService.createHtmlOutputFromFile('index');
}

function processForm(formObject) {
    var formBlob = formObject.myFile;
    var driveFile = DriveApp.createFile(formBlob);
    return driveFile.getUrl();
}

index.html

<script>
    function updateUrl(url) {
    var div = document.getElementById('output');
    div.innerHTML = '<a href="' + url + '">Got it!</a>';
}
</script>
<form id="myForm">
    <input name="myFile" type="file" />
    <input type="button" value="Submit"
    onclick="google.script.run
    .withSuccessHandler(updateUrl)
    .processForm(this.parentNode)" />
</form>
<div id="output"></div>

表单提交失败。我正在使用谷歌浏览器版本 30.0.1599.101 m 这出现在控制台中:未捕获的 NetworkError:表单提交失败。

这是应用程序:https://script.google.com/d/1yrgM20n1ZI99bChN2qtQWgGck36OccLN3A16Gn7tCPvsJw0EcK_ql7C5/edit?usp=sharing

【问题讨论】:

    标签: file-upload google-apps-script


    【解决方案1】:

    也许您应该将encoding="multipart/form-data" 属性添加到form 标记。

    【讨论】:

    • 我在脚本中添加了更改,但它仍然给我同样的错误。
    • 嗯...我在类似情况下遇到了同样的错误。然后我已经解决了。顺便说一句,另一个用户通过切断任何 chrome 扩展来解决它。
    【解决方案2】:

    如果尚未解决 - 您是否尝试将输入类型从“按钮”更改为“提交”?最重要的是,我还会尝试给它另一个值而不是“提交”,因为这可能会干扰实际的提交参数。

    【讨论】:

      猜你喜欢
      • 2012-05-16
      • 2014-02-15
      • 1970-01-01
      • 2017-07-22
      • 2015-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多