Created
July 25, 2015 21:14
-
-
Save eloone/ee0999d9ca0d78ae9466 to your computer and use it in GitHub Desktop.
upload file in angularjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(angular){ | |
angular.module('folio.components.project.thumbUpload', []) | |
.factory('ThumbUpload', ['$q', '$http', '$log', ThumbUploadProvider]); | |
function ThumbUploadProvider($q, $http, $log){ | |
function ThumbUploadService(){ | |
this.upload = function(file, filename){ | |
var deferred = $q.defer(); | |
var fd = new FormData(); | |
var filename = filename; | |
fd.append('filename', filename); | |
fd.append('file', file); | |
$http.post('/api/upload/thumb', fd, { | |
transformRequest: angular.identity, | |
headers: {'Content-Type': undefined} | |
}).success(function(data){ | |
deferred.resolve(data.data); | |
}).error(function(data){ | |
deferred.reject(data); | |
}); | |
return deferred.promise; | |
} | |
} | |
return new ThumbUploadService(); | |
} | |
}(window.angular)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment