I'm trying to make it possible to upload an excel file on a web application. But when I upload my file, there is an inifnite loop on the web application but the file is correctly uploaded, here is the code :
UPDATE
Node :
var storage = multer.diskStorage({
destination: function(req,file,cb) {
cb(null,'/uploads/')
},
filename: function(req,file,cb) {
cb(null, file.originalname);
}
});
var upload = multer({ storage : storage });
app.post('/upload', upload.single('file'), function(req,res) {
var tmp_path = req.file.path;
var target_path = './uploads/'+req.file.originalname;
var source = fs.createReadStream(tmp_path);
var dest = fs.createWriteStream(target_path);
var stream = source.pipe(dest);
stream.on('finish', function() {
res.send();
});
});
Angular :
$scope.uploadFile = function() {
var file = $scope.myFile;
var uploadUrl = "/upload";
var fd = new FormData();
fd.append('file',file);
}
$http.post(uploadUrl,fd,{
headers: {'Content-Type' : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}
});
With the solution that has been proposed by Pierre Emmanuel Lallemant, there is no more infinite loop, but the file is corrupted after the upload, its size is 0 Ko instead of 850 Ko.