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

can't upload jpg files: $file is null (in google chrome) #1971

Open nasserghiasi opened 7 years ago

nasserghiasi commented 7 years ago

PNG format is ok but I can't upload jpg format files, this is my code, Where did I make a mistake? I think library has problem with ngf-validate="{size: {min: 0, max: '2MB'}, width: {min: 200, max:1920}, height: {min: 100, max: 1080}}" Template Code:

            <div ngf-select="upload($file)" ngf-drop="upload($file)" class="drop-box"
                 ngf-drag-over-class="'dragover'" ngf-multiple="false"
                 ngf-pattern="'image/*'"
                 ngf-accept="'image/*'"
                 ngf-validate-fn="validateFile($file)"
                 ngf-run-all-validations="true"
                 ngf-validate-force="true"
                 ngf-validate="{size: {min: 0, max: '2MB'}, width: {min: 200, max:1920}, height: {min: 100, max: 1080}}">
              Drag and drop
            </div>
            <div ngf-no-file-drop>File Drag/Drop is not supported for this browser</div>

Javascript Code:

        $rootScope.upload = function (file) {
            if (!file) {
                toastr.error($translate.instant('File uploading failed!'));
                return false;
            }

            Upload.upload({
                url: UPLOAD_THUMBNAIL_ENDPOINT,
                data: {thumbnail: file}
            }).then(function (resp) {
                $rootScope.modalInstance.dismiss('cancel');

                $scope.landingPages[$rootScope.modalModel.landingPageIndex].thumbnailUrl = resp.data.thumbnailUrl;
                $scope.landingPages[$rootScope.modalModel.landingPageIndex].thumbnailUploaded = true;
            }, function (resp) {
                toastr.error($translate.instant('File uploading failed!'));
            }, function (evt) {
                var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
            });
        };
danielreiser commented 7 years ago

Have you checked the $error obj on the form yet? The file might not have passed the validation.