Guys, I'm having trouble uploading files with AngularJS, I am following the 
example of the site (https://jsfiddle.net/JeJenny/ZG9re/) but the file does 
not go the way folder server none.
 
Please help me. Here my code:
 
Scripted file for AngularJS:

;
(function () {
var module = angular.module('myApp.fileUpl', []);

module.directive('fileModel', ['$parse',function ($parse) {
    return {
           restrict: 'A',
           link: function(scope, element, attrs) {
           var model = $parse(attrs.fileModel);
           var modelSetter = model.assign;

           element.bind('change', function(){
              scope.$apply(function(){
                modelSetter(scope, element[0].files[0]);
              });
            });
        }
     };
}]);

    module.service('fileUpload', ['$http', function ($http) {
    this.uploadFileToUrl = function(file, uploadUrl){
     var fd = new FormData();
     fd.append('file', file);
    $http.post(uploadUrl, fd, {
     transformRequest: angular.identity,
     headers: {'Content-Type': undefined}
     })
     .success(function(){
         console.log(uploadUrl);
            alert("ok"); //  the message is displayed
     })
     .error(function(){
         console.log('error');
                    erro();
     });
    }
    }]);
    

})();
;
(function () {

    var MODULE_DEPENDENCIES = [
        'angular-growl',
        'ui.router',
        'myApp.painel',
        'myApp.loader',
'myApp.fileUpl'
    ];

    angular.module(CONSTANTS.APP, MODULE_DEPENDENCIES);

})();

...

;
(function () {

    var CONTROLLER = ['$scope', 'myApp.loader', 'fileUpload', function ($scope, 
loader, fileUpload) {

  $scope.uploadFile = function(){
        var file = $scope.myFile;
        console.log('file is ' );
        console.dir(file);
        var uploadUrl = "/servicos/upload/arquivos";
        fileUpload.uploadFileToUrl(file, uploadUrl);
    };
    }];

    angular.module(CONSTANTS.APP).controller('UppCtrl', CONTROLLER);

})(); 


Now in HTML:

<div ng-controller = "UppCtrl">
    <input type="file" file-model="myFile"/>
    <button ng-click="uploadFile()">upload me</button>
</div>


In the first file to put the command "alert (" ok")" to check if the 
function was even being called, the message is displayed, all apparently 
working right, but the file not up to the server.
 
Please, help!

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to