Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  136] [ 1]  / answers: 1 / hits: 31397  / 11 Years ago, wed, october 16, 2013, 12:00:00

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) {
console.log(result);
return result.data;
});
},


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


More From » ajax

 Answers
1

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
}


with



data: {
formdata
}

[#74942] Tuesday, October 15, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nikhilh

Total Points: 224
Total Questions: 89
Total Answers: 99

Location: Bahrain
Member since Fri, Sep 16, 2022
2 Years ago
;