处理文件上传与JavaScript和谷歌齿轮,有没有更好的解决方案? [英] Handling file uploads with JavaScript and Google Gears, is there a better solution?

查看:197
本文介绍了处理文件上传与JavaScript和谷歌齿轮,有没有更好的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


  1. 用户必须能够在对话框中选择多个文件进行上传。

  2. 我必须能够接收文件传输的状态更新。 (进度条)

  3. 我希望能够使用 PUT 请求,而不是 POST
  4. 我希望能够使用JavaScript轻松地将这些事件附加到现有的HTML元素。 I.E.文件选择应在<按钮> 点击触发

  5. 我希望能够控制响应/请求参数轻松使用JavaScript。

我不确定新的HTML5浏览器是否支持桌面/请求对象的齿轮使用,或者如果有一个Flash上​​传,有这些功能,我失踪了我的谷歌搜索。



使用齿轮上传代码的一个例子:

  //选择一些文件:
var desktop = google.gears.factory.create('beta.desktop');
desktop.openFiles(selectFilesCallback);

函数selectFilesCallback(files){
$ .each(files,function(k,file){
//这段代码实际上是通过一个队列,并创建一些状态栏
//但是在这里显示并不重要...
sendFile(file);
});


函数sendFile(file){
google.gears.factory.create('beta.httprequest');
request.open('PUT',upl.url);
request.setRequestHeader('filename',file.name);
request.upload.onprogress = function(e){
//给我%状态更新...允许e.loaded / e.total
};
request.onreadystatechange = function(){
if(request.readyState == 4){
//完成上传!
}
};
request.send(file.blob);
返回请求;

编辑:显然flash不能使用PUT请求,所以我已经把它改成like而不是must。

解析方案



Plupload是该块中最新的孩子之一,它使用最好的方法(HTML 5,Flash,Gears ,Silverlight): http://plupload.com/


So - I've been using this method of file uploading for a bit, but it seems that Google Gears has poor support for the newer browsers that implement the HTML5 specs. I've heard the word deprecated floating around a few channels, so I'm looking for a replacement that can accomplish the following tasks, and support the new browsers. I can always fall back to gears / standard file POST's but these following items make my process much simpler:

  1. Users MUST to be able to select multiple files for uploading in the dialog.
  2. I MUST be able to receive status updates on the transmission of a file. (progress bars)
  3. I would like to be able to use PUT requests instead of POST
  4. I would like to be able to easily attach these events to existing HTML elements using JavaScript. I.E. the File Selection should be triggered on a <button> click.
  5. I would like to be able to control response/request parameters easily using JavaScript.

I'm not sure if the new HTML5 browsers have support for the desktop/request objects gears uses, or if there is a flash uploader that has these features that I am missing in my google searches.

An example of uploading code using gears:

// 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;
}

Edit: apparently flash isn't capable of using PUT requests, so I have changed it to a "like" instead of a "must".

解决方案

(Spawned from a comment on the original question, per askers's suggestion.)

Plupload is one of the newest kids on the block and it uses the best method available (HTML 5, Flash, Gears, Silverlight): http://plupload.com/

这篇关于处理文件上传与JavaScript和谷歌齿轮,有没有更好的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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