I am trying to use baby parse (branch off of Papa Parse) to take a csv file and parse the data to Json. The csv file I am testing is very straight forward:
Column1,Column2,Column3
1,2,3
3,2,1
So far I am successfully loading the file using ng-file-upload to load the csv file via the browser.
I am now trying to use baby parse to take this file and convert the data to JSON.
Below is what I have so far:
The controller
// Watch for a csv file being uploaded.
$scope.$watch(function() {
return $scope.file
}, function(){
$scope.upload($scope.file);
});
$scope.upload = function(file){
if(file){
Upload.upload({
url: 'api/admin/uploadCsv',
method: 'POST',
data: {userId: $scope.user._id},
file: file
}).progress(function(evt){
console.log("firing");
}).success(function(data){
}).error(function(error){
console.log(error);
})
}
};
On file upload the upload function is called and calls the server controller. The file uploaded is passed to the upload function which I am then attempting to pass to the parse method.
module.exports.uploadCsv = function(req, res){
var file = req.files.file;
var userId = req.body.userId;
parsed = babyparse.parse(file.path, babyParseConfig);
console.log("data is " + (JSON.stringify(parsed.data)));
...
The console.log outputs the following:
data is {"data":[],"errors":[],"meta":{"delimiter":",","linebreak":"\n","aborted":false,"truncated":false,"fields":["..\\App\\uploads\\565b8feecddbb1e41b7aa839test.csv"]}}
I can not understand why data:[] is empty given what the csv file looks like.