使用JavaScript和Google Gears处理文件上传是否有更好的解决方案?

gna*_*arf 6 html javascript flash file-upload google-gears

所以 - 我一直在使用这种文件上传方法,但似乎Google Gears对实现HTML5规范的新浏览器支持不足.我听说过几个频道的弃用词,所以我正在寻找能够完成以下任务并支持新浏览器的替代品.我总是可以回到齿轮/标准文件POST,但这些以下项目使我的过程更简单:

  1. 用户必须能够在对话框中选择多个文件进行上传.
  2. 必须能够接收有关文件传输的状态更新.(进度条)
  3. 我希望能够使用PUT请求而不是POST
  4. 我希望能够使用JavaScript轻松地将这些事件附加到现有HTML元素.IE应该在<button>单击时触发文件选择.
  5. 我希望能够使用JavaScript轻松控制响应/请求参数.

我不确定新的HTML5浏览器是否支持桌面/请求对象齿轮使用,或者是否有闪存上传器具有我在谷歌搜索中缺少的这些功能.

使用齿轮上传代码的示例:

// select some files:
var desktop = google.gears.factory.create('beta.desktop');
desktop.openFiles(selectFilesCallback);

function selectFilesCallback(files) {
  $.each(files,function(k,file) {
    // this code actually goes through a queue, and creates some status bars
    // but it is unimportant to show here...
    sendFile(file);
  });
}

function sendFile(file) {
  google.gears.factory.create('beta.httprequest');
  request.open('PUT', upl.url);
  request.setRequestHeader('filename', file.name);
  request.upload.onprogress = function(e) {
    // gives me % status updates...  allows e.loaded/e.total
  };
  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      // completed the upload!
    }
  };
  request.send(file.blob);
  return request;
}
Run Code Online (Sandbox Code Playgroud)

编辑:显然flash无法使用PUT请求,因此我将其更改为"喜欢"而不是"必须".

jan*_*sen 1

(根据提问者的建议,源自对原始问题的评论。)

Plupload 是最新的产品之一,它使用可用的最佳方法(HTML 5、Flash、Gears、Silverlight):http://plupload.com/