Upload HUGE file > 2GB to nodejs (n Firefox)

2019-04-02 10:49发布

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!

1条回答
时光不老,我们不散
2楼-- · 2019-04-02 11:16

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

查看更多
登录 后发表回答