I'm using angularFileUpload module in my project. It working fine but I want to sending additional data with my file/s but I can't.
var uploader = $scope.uploader = Upload.upload({
url: 'api/photos/upload/propertyphoto',
type:'post',
data:{name:'my name'},
headers:{
csrf_token:CSRF_TOKEN,
'X-XSRF-TOKEN':X_XSRF_TOKEN
}
});
Photo uploading working fine. but when I receive the data using $_POST['name'] thats does not work.
I found the solution:
To send additional data or form data with angularFileUpload, you need to include the formData key.
Example:
var uploader = $scope.uploader = new FileUploader({
url: 'api/photos/upload/propertyfeaturephoto',
type: 'post',
formData: [{mydata: 'this is my data'}],
headers: {
csrf_token: CSRF_TOKEN
},
success:function(resp) {
console.log(resp);
}
});
Here formData allows the developer to send additional data or form data to server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With