ng-file-upload icon indicating copy to clipboard operation
ng-file-upload copied to clipboard

Possibly unhandled rejection

Open Noushid opened this issue 7 years ago • 6 comments

got this error when uploading: Possibly unhandled rejection: {"data":"<p>The upload path does not appear to be valid.</p>","status":401,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"http://localhost:8080/upload","data":{"file":{"$ngfBlobUrl":"blob:http://localhost:8080/92a870df-21ce-4616-91e5-0e59b529cf3a","$ngfWidth":425,"$ngfHeight":425,"upload":{},"progress":100}},"_isDigested":true,"_chunkSize":null,"headers":{"Accept":"application/json, text/plain, */*"},"_deferred":{"promise":"..."}},"statusText":"File Upload Error"} how can i fix ?

Noushid avatar Apr 26 '17 10:04 Noushid

I have the same error while uploading big files. Did you find any solution ?

I found this to disable the error (working on angular 1.6) yourapp.config(['$qProvider', function($qProvider) { $qProvider.errorOnUnhandledRejections(false); }]);

elarion avatar Jun 20 '17 23:06 elarion

Same here, I don't like the workaround as this error on the console is useful on our own code. ngFileUpload should handle its promises properly so when I use

Upload.upload({
                    url: 'some/url',
                    data: {file: image, model: imageInfo}
                }).then(function () {
                    //code on success
                }, function (error) {
                    //code on error
                });

no error should be thrown.

mpellerin42 avatar Jun 27 '17 11:06 mpellerin42

$scope.uploadFiles = function(file) {
		$scope.attach = file;
	    file.upload = Upload.upload({
	        url: 'sendemail',
	        data: {file: file} 
	    });
		console.log($scope.attach);
    }

Anyone can help me with the same error? How can I fix it?

kapeeeek avatar Sep 01 '17 12:09 kapeeeek

For what it's worth : I've been digging around in Upload.upload's source code and found out this:

https://github.com/danialfarid/ng-file-upload/blob/d911c553d0c1be76276a3b50ad5e3e8345c91747/src/upload.js#L153-L165

This is the deffered's promise that is returned when calling Upload.upload, so using either:

Upload.upload({
   ...
}).then(function success() {
   ...
}, function error() {
   ...
})

Or

Upload.upload({
   ...
}).success(function success() {
   ...
}).error(function error() {
   ...
})

Should work.

Eregrith avatar Oct 03 '17 07:10 Eregrith

@Eregrith It actually doesn't work--I tried implementing both rejection and catch, but neither squashes the error. I'm creating a PR now, but can't tell how to build the project since the author didn't include instructions. Hopefully he'll respond decently quickly since this is a bit of a pain and shouldn't warrant us squashing all unhandled promise rejections since we track and fix them as a matter of best practice.

arcreative avatar Apr 30 '19 18:04 arcreative

Actually nevermind, it's old enough to be using grunt, got it built :-)

arcreative avatar Apr 30 '19 18:04 arcreative