I am working with a simple file upload from client to server . Below is what i tried.
eReaderBook.controller('browseCtrl',['$scope',"$http",function($scope,$http){
$scope.fileName ="";
$scope.imageName ="";
$scope.uploadFile = function(){
var data1 = new FormData();
data1.append('input_file_name', $('#fileName').prop('files')[0]);
data1.append('input_image_name', $('#imageName').prop('files')[0]);
if($scope.fileName!="" && $scope.imageName!="")
{
$http({
url: '/upload',
method: "POST",
data: data1
})
.then(function(response) {
console.log("success")
},
function(response) { // optional
console.log("failed")
});
}
};
}])
node .js
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(multer());
app.post('/upload',function(req,res)
{
console.log("aaa");
res.send("hi")
});
But when i send request to nodejs server it throws an error Error: invalid json at parse (d:\MeanTest\node_modules\body-parser\lib\types\json.js:83:15)
What i am doing wrong here...