上传HUGE文件> 2GB到nodejs(n Firefox) [英] Upload HUGE file > 2GB to nodejs (n Firefox)

查看:156
本文介绍了上传HUGE文件> 2GB到nodejs(n Firefox)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把我的例子作为基本的可能了。我尝试上传一个超过2 GB的大文件到我的服务器,但是我收到一个错误仅在Firefox中。在Chrome似乎工作好。它说错误:连接断开。有人可以解释我为什么,我可以做些什么?

pre $ var http = require(http);
var url = require(url);
$ b $ http.createServer(function(request,response){
switch(url.parse(request.url).pathname){
case/:
displayForm(request,response);
break;
case/ upload:
response.writeHeader(200,{Content-Type:text / html});
response.end(
'< h1> File Uploaded!< / h1>'
);
break;
}
})。listen 1234);

var displayForm = function(request,response){
response.writeHeader(200,{Content-Type:text / html});
response.end(
'< form action =/ uploadmethod =postenctype =multipart / form-data>'+
'< input type = filename =uploadFile>'+
'< input type =submitvalue =Upload!>'+
'< / form>'
);
};

编辑:我刚刚意识到它只发生在 Firefox ,而不是Chrome浏览器!

解决方案

对于这样的大文件,我推荐你用 FileReader ,用小于code> Blob 或 Blobbuilder Socket.io)按进度条块连接文件块,连接服务器上的块。当你发送完最后一个数据块时,你的后端就会得到完整的文件。

你也可以在cookie / LocalStorage中保存当前数据块号码,以便在连接中断的情况下继续传输数据。 / p>

PS对于古老的IE和其他狗屎,有使用Blob,谷歌它的Flash插件。
$ b

不同浏览器的POST请求的PSS最大文件大小:I've made my example as basic possible. I try to upload a huge file, more than 2 GB, to my server but I receive an error only in Firefox. In Chrome seems to work allright. It says something like "Error: Connection broken". Could someone explain me why and what could I do about it?

var http       = require("http");
var url        = require("url");

http.createServer(function (request, response) {
    switch(url.parse(request.url).pathname) {
        case "/":
            displayForm(request, response);
            break;
        case "/upload":
            response.writeHeader(200, {"Content-Type":"text/html"});
            response.end(
                '<h1>File Uploaded!</h1>'
            );
            break;
    }
}).listen(1234);

var displayForm = function(request, response) {
    response.writeHeader(200, {"Content-Type":"text/html"});
    response.end(
        '<form action="/upload" method="post" enctype="multipart/form-data">' +
            '<input type="file" name="uploadFile">' +
            '<input type="submit" value="Upload!">' +
        '</form>'
    );
};

EDIT: I just realized it only happens in Firefox, not in Chrome!

For such large files I recommend you to read your file with FileReader, chunk it on small binary pieces with Blob or Blobbuilder and transfer (by Socket.io) the file chunk by chunk with progress bar, concatenating the chunks on the server. When last chunk is sent - you got full file on your backend.

You can also save current chunk number in cookie/LocalStorage in case of connection breaks to continue transfer.

P.S. For ancient IE's and other shit there is flash plugin for using Blobs, google it.

P.S.S Max file size by POST requests for different browsers: http://motobit.com/help/scptutl/pa98.htm

这篇关于上传HUGE文件&gt; 2GB到nodejs(n Firefox)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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