Saturday 10 June 2017

Infinite loop uploading file multer/express

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 :

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);
        source.pipe(dest);
});

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'}
});



via Tewan

No comments:

Post a Comment