New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change http headers of request #92

Closed
ghost opened this Issue Mar 21, 2014 · 10 comments

Comments

Projects
None yet
8 participants
@ghost

ghost commented Mar 21, 2014

In my application I have token-based security setup. For this to work I setup an http interceptor in angular that appends an authentication token to any $http request. However, angular-file-upload doesn't use $http and instead relies on XHR. How would I go about intercepting an XHR request or just specifying headers to be send with the upload request? Thanks in advance.

@kulicuu

This comment has been minimized.

Show comment
Hide comment
@kulicuu

kulicuu Mar 23, 2014

This is listed in the uploader API under headers-- also form data might help.

kulicuu commented Mar 23, 2014

This is listed in the uploader API under headers-- also form data might help.

@nervgh

This comment has been minimized.

Show comment
Hide comment
@nervgh
Owner

nervgh commented Mar 23, 2014

@nervgh nervgh closed this Apr 6, 2014

@nervgh nervgh added the question label Apr 8, 2014

@markzolotoy

This comment has been minimized.

Show comment
Hide comment
@markzolotoy

markzolotoy Dec 9, 2015

I need exactly the same thing. I need to intercept an upload and refresh a token when it expires. But my interceptor does not intercept the upload call. What can I do?

markzolotoy commented Dec 9, 2015

I need exactly the same thing. I need to intercept an upload and refresh a token when it expires. But my interceptor does not intercept the upload call. What can I do?

@thomashagstrom

This comment has been minimized.

Show comment
Hide comment
@thomashagstrom

thomashagstrom May 18, 2016

For all my other request, seting headers on $http is sufficient. I wonder why this doesn't seem to work for FileUpload?

http.defaults.headers.common["Authorization"] = "Bearer " + tokenInfo.accessToken;

thomashagstrom commented May 18, 2016

For all my other request, seting headers on $http is sufficient. I wonder why this doesn't seem to work for FileUpload?

http.defaults.headers.common["Authorization"] = "Bearer " + tokenInfo.accessToken;

@josencv

This comment has been minimized.

Show comment
Hide comment
@josencv

josencv May 18, 2016

Collaborator

This is because the uploader doesn't use the $http service. It uses native javascript xhr object. Maybe in the future the $http service will be supported. For now, you'll have to add the authorization headers in the uploader directly:

var uploader = new FileUploader();
uploader.headers["Authorization"] = "Bearer " + tokenInfo.accessToken;

Hope it helps,

Collaborator

josencv commented May 18, 2016

This is because the uploader doesn't use the $http service. It uses native javascript xhr object. Maybe in the future the $http service will be supported. For now, you'll have to add the authorization headers in the uploader directly:

var uploader = new FileUploader();
uploader.headers["Authorization"] = "Bearer " + tokenInfo.accessToken;

Hope it helps,

@thomashagstrom

This comment has been minimized.

Show comment
Hide comment
@thomashagstrom

thomashagstrom May 19, 2016

Yeah, that worked great. Thanks!

thomashagstrom commented May 19, 2016

Yeah, that worked great. Thanks!

@mrgoos

This comment has been minimized.

Show comment
Hide comment
@mrgoos

mrgoos Jun 4, 2017

@josencv - are we in the future yet? 😉

mrgoos commented Jun 4, 2017

@josencv - are we in the future yet? 😉

@theo4u

This comment has been minimized.

Show comment
Hide comment
@theo4u

theo4u Jun 4, 2017

Collaborator

coming up soon i guess @josencv

Collaborator

theo4u commented Jun 4, 2017

coming up soon i guess @josencv

@theo4u

This comment has been minimized.

Show comment
Hide comment
@theo4u

theo4u Jun 4, 2017

Collaborator

continues here #434

Collaborator

theo4u commented Jun 4, 2017

continues here #434

@tusharwalzade216

This comment has been minimized.

Show comment
Hide comment
@tusharwalzade216

tusharwalzade216 Dec 7, 2017

@josencv, your solution worked great! Thanks a lot

tusharwalzade216 commented Dec 7, 2017

@josencv, your solution worked great! Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment