Angular File Upload ( CORS ) with credentials is not working


I am using angular file module:

I am facing difficulties in uploading to an api which requires credentials. I am passing ‘withCredentials : true’. This doesn’t seem to work.

I am able to successfully upload on another setup of same API without credentials. CORS is set up properly on this API, other GET / POST calls ( CORS ) work on this API.

It would be great if you could guide me if I am missing something here.

Error :

“NetworkError: 401 Unauthorized –”; doUpload 2 Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at hostname/notification/doUpload. This can be fixed by moving the resource to the same domain or enabling CORS. I swapped with an API host not requiring credentials and that worked.

                    url: NotificationAPI.hostName + '/notification/doUpload',
                    headers: {'Content-Type' : 'multipart/form-data'},
                    fields: fields,
                    file: file,
                    withCredentials : true,


I think I’ve just had the same issue as you. I solved it by setting ‘Access-Control-Allow-Credentials’ to true in the response headers.

Answered By – Neil Bryson

Answer Checked By – David Goodson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.