Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send additional data with angularFileUpload

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.

like image 531
Nahid Bin Azhar Avatar asked May 02 '26 07:05

Nahid Bin Azhar


1 Answers

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.

like image 190
Nahid Bin Azhar Avatar answered May 04 '26 01:05

Nahid Bin Azhar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!