I am new to Mean and nodejs. I have a old project with old dependencies. And I am trying to upload image file to server using angular js. But it does not work. I don't know how to retrieve image file data, name, type, etc at both client and server side.
Client js
$scope.uploadFile = function(files,index) {
console.log("uploading file");
console.log("sticker index:" + index);
console.log("StickerGroupID:"+ $scope.stickergroup._id);
console.log("file:"+ files[0].name);
console.log("sticker : " + $scope.stickergroup.stickers[index].stickername );
$scope.stickergroup.stickers[index].stickerFileName = files[0].name ;
console.log("sticker path now:" +$scope.stickergroup.stickers[index].stickerFileName);
var fd = new FormData();
fd.append("file", files[0]);
fd.append("filename", files[0].name);
//put an upload file to temp location.
$http.post("/stickergroups/uploadstickers", fd, {
// withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity});
Server js
exports.uploadTempFile = function(req, res) {
console.log("uploading start");
console.log("file required :" +req.files);
var imagefile = req.files.file;
var tempDirectorySticker = tempDirectory + imagefile.originalFilename;
console.log("temp directory" + tempDirectorySticker );
fs.readFile(imagefile.path, function (err, data) {
fs.writeFile(tempDirectorySticker, data, function (err) {
res.redirect("back");
});
});};
req.files is resulting "undefined".
Thanks