处理文件上传与JavaScript和谷歌齿轮,有没有更好的解决方案? [英] Handling file uploads with JavaScript and Google Gears, is there a better solution?
问题描述
- 用户必须
PUT
请求,而不是 POST $
我希望能够使用JavaScript轻松地将这些事件附加到现有的HTML元素。 I.E.文件选择应在<按钮>
点击触发
我希望能够控制响应/请求参数轻松使用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:
- Users MUST to be able to select multiple files for uploading in the dialog.
- I MUST be able to receive status updates on the transmission of a file. (progress bars)
- I would like to be able to use
PUT
requests instead ofPOST
- 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. - 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屋!