如何使用一个文件输入元素上传多个文件 [英] How to upload multiple files using one file input element

查看:140
本文介绍了如何使用一个文件输入元素上传多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用一个文件输入元素将多个文件上传到使用html表单的云端硬盘。这似乎只适用于一个文件,虽然文件选择器允许选择多个文件。回到脚本日志查看器中,我只能看到我上传的两个文件中的一个文件。这是不受支持的,或者我会错误的方式吗?

I'm trying to use one file input element to upload multiple files to Drive using html form. This seems to work only for one file, although the file picker allows selecting multiple files. Back in the script log viewer, I only see one file captured of the two I uploaded. Is this unsupported, or am I going the wrong way about it?

Code.gs:

function logForm(form) {
  Logger.log(JSON.stringify(form));
  return true;
}

index.html:

index.html:

<html>
  <form id="uploadTest" enctype="multipart/form-data">
    <input type="file" multiple="multiple" name="fileUpload">
    <input type="button" id="upload" value="upload"
    onclick="google.script.run.logForm(document.getElementById('uploadTest'));">
  </form>
</html>

日志视图:

{"fileUpload":{"contents":"GIF87a\u0001\u0000\u0001\u0000�
\u0000\u0000��̖��,\u0000\u0000\u0000\u0000\u0001\u0000
\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;",
"type":"image/gif","name":"1x1.gif","length":35}}


推荐答案

当您单击文件字段的浏览按钮时,在对话框中选择多个文件只会发生支持HTML5的新浏览器。它不会允许多个选择旧的浏览器。对于旧版浏览器来说,唯一不错的解决方案是Flash或JavaScript插件。这里是jquery上传者的一个很好的资源(一些支持多个文件): http:// creativefan的.com / 10 Ajax的jQuery的文件上传/ 。因此,我的建议是使用一些插件,以便它支持旧的和新的浏览器。

The multiple file select in the dialog when you click on the browse button of the file field happens only for the new browsers supporting HTML5. It wont allow multiple select for old browsers. For older browsers the only good solutions are flash or javascript plugins. Here is a good resource for jquery uploaders ( some support multiple files ): http://creativefan.com/10-ajax-jquery-file-uploaders/. Hence my suggestion is use some plugin so that its supported on old as well as the new browsers.

这篇关于如何使用一个文件输入元素上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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