Skip to content

Instantly share code, notes, and snippets.

@eloone
Created July 25, 2015 21:14
Show Gist options
  • Save eloone/ee0999d9ca0d78ae9466 to your computer and use it in GitHub Desktop.
Save eloone/ee0999d9ca0d78ae9466 to your computer and use it in GitHub Desktop.
upload file in angularjs
(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