I am trying to make image upload from iphone. I am using ionic with cordova plugins in fontend and express/node.js in backend. This code works fine when i try in localhost. but when i run in heroku i am getting this error
error: ENOENT, open /var/mobile/Containers/Data/Application/../../image.jpg
I am using multer to handle multipart/form-data
on expressjs/node.js side i have
router.post('/me/avatar', ensureAuthenticated, function(req, res) {
fs.readFile(String(req.body.imageUrl).substring(7), function(err, data) {
//using String(req.body.imageUrl).substring(7) to avoid file path like "file:///var/mobile/.." in ios simulator and iphone
if (err) {
console.log(err)
res.send({
message: "Error"
})
};
});
})
on ionic side i have
$scope.updateAvatar = function() {
var options = {
maximumImagesCount: 1
};
$cordovaImagePicker.getPictures(options)
.then(function(results) {
$http.post(API_URL+"/users/me/avatar", {
imageUrl: results[0]
})
.success(function(response) {
var random = (new Date()).toString();
$scope.avatar = response.fullPath + "?cb=" + random;
})
}, function(error) {
// error getting photos
});
},