Skip to content
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

Pass HTTP headers along with URL #36

Closed
shreenil opened this issue Jul 10, 2019 · 4 comments
Closed

Pass HTTP headers along with URL #36

shreenil opened this issue Jul 10, 2019 · 4 comments

Comments

@shreenil
Copy link

shreenil commented Jul 10, 2019

My API is requesting Authorization header to access the files. How do i pass headers while passing URL in pdfSrc?

@codehippie1
Copy link
Contributor

@shreenil I am afraid, I am not able to understand your issue. What is the url you are passing? The component does not make any http calls. You have to make the call to api and feed the resulting byte array into the component. Look at this example: https://ng2-pdfjs-viewer.azurewebsites.net/bytearray

@shreenil
Copy link
Author

@codehippie1, If you look at this example https://ng2-pdfjs-viewer.azurewebsites.net/home, one can pass url of document in pdfSrc.

Though, there is a note saying we need to have documents in 'assets' folder, I've tried passing my web API URL(which is returning byte stream) in pdfSrc, And it successfully loads the PDF if there is no authorization needed to access that webAPI.

Unfortunately, my web API is accessible to only 'Authenticated' users. So, i need to pass 'access-token' in API request headers to access the API URL.

Why i need to directly pass URL in pdfSrc? Because, it may be possible that my PDF is very lengthy and i may need to load it asynchronously.

It would be great if I have option(feature) to pass headers if the URL is mobile.

@codehippie1
Copy link
Contributor

I sort of understood the problem. Please post relevant code here, both server side and client side. I will try to get headers added if it is feasible.

Please note, source url is an underlying PDFJS's feature. Altering it may need tweaking.

@codehippie1
Copy link
Contributor

codehippie1 commented Jul 23, 2019

@shreenil I did my research and this is not directly available. viewerjs internally uses http request to set urls. (E.g .src etc). You will only be able to change http headers if the url is requested over javascript(Like ajax).
Further info: https://stackoverflow.com/questions/24130004/adding-http-headers-to-window-location-href-in-angular-app

The work around is to use the byte array mechanism. You can set http headers using it. (Example here - https://ng2-pdfjs-viewer.azurewebsites.net/bytearray )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants