3

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Under what circumstances are you using $_POST['name']?

The only difference I can see with your code and my (working) code is that I don't have a type: 'post', seems to be ok without it.

I have a nodejs backend running Express. Express passes the data values through to node in a request object and I access it via req.body.name.

Are you sure your url is calling your backend correctly?

2 Comments

oh, I used PHP for backend. so by using $_POST I just retrieve form data. Thank you for your response. I solve it :)
Here I just attached formData to sending additional data with the request var uploader=$scope.uploader=new FileUploader({ url: 'api/photos/upload/propertyfeaturephoto', type:'post', formData:[{mydata:'this is my data'}], headers:{ csrf_token:CSRF_TOKEN, 'X-XSRF-TOKEN':X_XSRF_TOKEN }, success:function(resp){ console.log(resp); } });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.