Reputation: 1128
How can I manually trigger file uploads within an action of an angular controller?
This is my controller
angular.module('angular-app', ['blueimp.fileupload'])
.controller('NewsController', function($scope, $http) {
......
$scope.SaveNews = function() {
var url = baseUrl + '/Post',
data = $scope.News;
$http({
url: url,
method: 'POST',
data: data
}).success(function(data) {
$scope.News = data.Data;
---> something.submit(); // <--- THIS IS THE FILES SUBMIT
}
}).error(function(data) {
ShowAlert(data.Success);
});
};
I cannot trigger anything, any idea?
Upvotes: 2
Views: 1451
Reputation: 36
I had the same problem.
My problem was getting the list of files. I solved this way
//The list of files
$scope.$on('fileuploadchange', function (event, files) {
$scope.Files = files.files;
});
//The action triggered manually
$scope.SubmitAction = function(){
$('#fileUploadID').fileupload('send', {files: $scope.Files});
}
Pay attention to one thing, every time it is called "fileuploadchange" in the variable "files" you can find only the latest items added!
Upvotes: 1
Reputation: 8646
Check documentation: https://github.com/blueimp/jQuery-File-Upload/wiki/API#wiki-programmatic-file-upload
$('#your-selector').fileupload('send', {files: your.data});
Upvotes: 0