flashpunk flashpunk - 3 months ago 10x
AngularJS Question

AngularJs Ajax POST form with file upload

I'm trying to set up a form to be submitted using an ajax request to an api that has already been built using Ajax. For some reason the file just doesn't want to transfer to the system although there is already a back end built to handle this, and it works fine.

My service looks like this based on a tutorial I found here: http://badwing.com/multipart-form-data-ajax-uploads-with-angularjs/

addActivity: function(url){
return $http({
method: 'POST',
url: REQUEST_URL + 'Volunteering/AddActivity?token=' + token + url,
headers: {
'Content-Type': 'multipart/form-data'
data: {
file: $scope.file
transformRequest: formDataObject
then(function(result) {
return result.data;

I have a feeling it's just something really minor that i'm missing, can anyone offer some help?


I faced a similar problem.

The solution is to use formData

var formData = new FormData();
formData.append("file", $scope.file);

and replace

data: {
            file: $scope.file


data: {