2

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?

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

Comments

0

Check documentation: https://github.com/blueimp/jQuery-File-Upload/wiki/API#wiki-programmatic-file-upload

$('#your-selector').fileupload('send', {files: your.data});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.