I'm using Angular-File-Upload, the problem that is I can't send a formData along with the file. Following is my code:
$scope.addProducts = function(){
console.log($scope.product);
ProductApi.addProduct($scope.product)
.then(function(response){
ngNotify.set('Your product has been added!', {
position: 'bottom',
duration: 2000
});
$scope.product_id = response.data;
uploaderImages.uploadAll();
})
.catch(function(response){
console.log(response.data);
})
}
What the above code does is, once the form is submit, the form will is send via api call. The response will be an product_id and uploaderImages.uploadAll(); is triggered!!(This stuff work perfectly). Following is uploaderImages that will post file to server:
var uploaderImages = $scope.uploaderImages = new FileUploader({
url: '/api/productimg',
onBeforeUploadItem: function(prod){
var ids = $scope.product_id
var prodid = { proid: $scope.product_id} ---> empty
prod.formData.push(prodid)
console.log($scope.product_id) ----> product_id = 32
},
onCompleteAll: function(){
console.log($scope.product_id); ----> product_id = 32
},
onSuccessItem: function(prodId,response,status,headers){
}
});
I had no idea how to tackle this prob, proid:product_id return as [object Object], if I assign proid as a fixed integer ie proid:23, it works.
PLEASE HELP!!!!!