I am using sails version 0.11 which comes bundled with skipper for file uploads. I need to upload big files of over 100 MB in size at least.
Now I don't want the file upload to complete before I start further processing of the file on server. I want to read the file stream while it is being uploaded. Here is how I am trying to achieve the same:
var csv = require("fast-csv");
bulk: function (req, res){
function parseEntry(entry){
return entry
}
var inputStream = req.file('employees');
var csvStream = csv();
inputStream.pipe(csvStream);
csvStream.on("data", function (data){
count++
// skip invalid records
var parsedData = parseEntry(data);
console.log(parsedData);
});
csvStream.on("end", function(){
// console.log("total time taken in minutes:", timeTaken);
return res.json(200, {"status": 1, "message": "successfully uploaded the file"});
});
}
But my logs only show up the end event and no data event is being captured. I read in the documentation that req.file("filename")
will return stream of file streams. But how do I access the particular file stream I need since I am only uploading a single file?