i have a problem with large file upload to Gridfs via gridfs-stream node module. I have tried to upload smaller files and it's working nicely but when i try to upload larger file (~2gb and more) the node.js server is giving me this error:
Error: Request aborted
at IncomingMessage.onReqAborted (D:\ProjectName\node_modules\express\node_modules\connect\node_modules\multiparty\index.js:131:17)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1911:11)
at Socket.serverSocketCloseListener (http.js:1923:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:466:12)
My code is as follows, also this is all done on local node server:
//crud.js file
var config = require('./config.js')
var fs = require('fs')
var Grid = require('gridfs-stream');
var gfs = Grid(config.db, config.mongo);
exports.uploadFile = function (req, res) {
var tempfile = req.files.filename.path;
var origname = req.files.filename.name;
var writestream = gfs.createWriteStream({ filename: origname });
fs.createReadStream(tempfile)
.on('end', function () {
res.send('<p><h1>Upload Complete!</h1><p>');
}).on('error', function () {
res.send('Error, upload failed!');
}).pipe(writestream);
}
And my main server.js file:
app.configure(function () {
app.use(express.compress());
app.use('/', express.static(__dirname + '/upload'));
app.set('view engine', 'html');
app.use(express.logger('dev'));
app.use(express.bodyParser({limit: '1000000mb'}));
app.use(express.methodOverride());
app.use(app.router);
});
app.post('/', crud.uploadFile)
And lastly my client:
<div class="col-lg-4">
<form id="form" method="post" action="" enctype="multipart/form-data">
<input type="file" id="file" name="filename" class="btn btn-warning">
<br>
<input type="submit" value="Upload file" class="btn btn-primary">
</form>
</div>
Also i think i should mention that after i get the above error, file starts to upload again but still fails. Again, smaller files are no problem. So my question is how am i able to stream large files effectively with this method, or is there a better method for doing this? Thanks.