danialfarid / ng-file-upload

Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
MIT License
7.87k stars 1.6k forks source link

Upload object undefined #1981

Open alexandroscgb opened 7 years ago

alexandroscgb commented 7 years ago

Hi.

I'm trying to upload the file but it keeps saying 'cannot read upload property of undefined' in this part of the controller: $scope.upload = function (file) { Upload.upload.... The object Upload, being a parameter of the controller, is undefined.

My controller: .controller('paramController',['$scope','Upload', function ($scope,$state,Upload, $location,$mdSidenav,mainService,loginService,resourceAccessService)

The function inside the controller: $scope.upload = function (file) { Upload.upload({ url: 'upload/url', data: {file: file, 'username': $scope.username} }).then(function (resp) { console.log('Success ' + resp.config.data.file.name + 'cargado. Respuesta: ' + resp.data); }, function (resp) { console.log('Error: ' + resp.status); }, function (evt) { var progressPercentage = parseInt(100.0 * evt.loaded / evt.total); console.log('Progreso: ' + progressPercentage + '% ' + evt.config.data.file.name); }); };

And my html: `

                    <img ngf-src="logoImage" class="thumb" ngf-resize="{width: 40, height: 40, quality: 0.9}">
                    <i ng-show="parametrizacionForm.logoFile.$error.maxHeight" style="color:red">Max height: 110</i><br/>
                    <i ng-show="parametrizacionForm.logoFile.$error.maxWidth" style="color:red">Max width: 180</i><br/>
                    <i ng-show="parametrizacionForm.logoFile.$error.pattern" style="color:red">JPG, JPEG o PNG solamente</i>
                    <span class="progress" ng-show="logoImage.progress >= 0">
                        <div style="width:{{logoImage.progress}}%" ng-bind="logoImage.progress + '%'" class="ng-binding"></div>
                    </span>
                    <span ng-show="logoImage.result">Upload successful</span>`

Whenever I hit Upload, it says some field have to be filled, but I do not want it like that, just to upload the file. And when filled, the javascript error above shows up.

What am I doing wrong?

malikzee807 commented 3 years ago

Same issue :(