Merott / nativescript-pdf-view

A basic PDF viewer plugin for NativeScript. Now maintained by @madmas: github.com/madmas/nativescript-pdf-view
Other
32 stars 35 forks source link

PDF URLs with headers and authorisations #22

Open sakozz opened 7 years ago

sakozz commented 7 years ago

Is it possible or any work around to include the headers to request? After looking into the source code, it seems that we can include for Android but i am not sure how we can achieve for iOS.

Merott commented 7 years ago

Perhaps it would also be possible on iOS, as suggested in this SO answer, with the caveat being that only the first request would have the headers. That shouldn't normally be an issue (I think), though there is a potential that any hyperlinks within the PDF might not work. Then again, that's not a use case I had in mind for this plugin, and I don't know if anyone uses it like that.

I think a more robust solution would be to download the file to temp storage first, and then load as a local file. In fact, the Android implementation of this plugin does exactly that in a private cacheThenLoad method, because as it currently stands, AndroidPdfViewer doesn't support loading remote files.

So, I think the best solution would be to make iOS also cache PDF files before loading them into the WKWebView, and then use the HttpRequestOptions argument on http.getFile to set whatever headers you'd like to use.

I'll try to find the time to do this at some point, but feel free to beat me to it and submit a PR. In the meantime, you could simply use NativeScript's http to cache your PDF before passing it to this plugin.

sakozz commented 7 years ago

Thanks for your response. I find the Android implementation more readable and probably reliable. However, being very beginner with Nativescript, i am not very confident with the iOS implementation.

Anyways, i will try and shuffle around and let you know if i get any progress.