0

I have a very simple form where users can write posts and insert a thunbnail image, the problem is that whenever i append the multipart header to the ajax request, the data doesn't get transmitted to the server. This is my ajax service:

angular.module('kadir.services', [])
.factory('cuService', function($q,$http) {
var newPost = function(data){
var deferrer = $q.defer();
  $http({
    method:"POST",
    data:data,
    headers:{'Content-Type': 'multipart/form-data'},
    url:new_app_url}).then(function(res){
      //success
      deferrer.resolve(res.data);
    },function(fail){
      //fail
      deferrer.reject(fail.data);
    });
 return deferrer.promise;
}
  return {
   newPost:newPost 
  }
 });

I don't want to pull down any third party directives, i want to do this in plain angularjs (Unless i really really have to).

Kadir Damene
  • 358
  • 1
  • 3
  • 10
  • Can you show us the source of your `formData`? That's the key element of the problem, I guess. – Kindzoku Sep 10 '16 at 21:49
  • Anyways, read this article https://uncorkedstudios.com/blog/multipartformdata-file-upload-with-angularjs. Maybe it's better to use 3rd party library, instead inventing a bicycle... And here is a good answer: http://stackoverflow.com/questions/18571001/file-upload-using-angularjs – Kindzoku Sep 10 '16 at 22:00

0 Answers0