webodf / ViewerJS

ViewerJS: Document Reader in JavaScript
http://viewerjs.org
1.94k stars 419 forks source link

Not able to display PDF from Custom URL even though the PDF is downloaded successfully #185

Open MehdiFal opened 8 years ago

MehdiFal commented 8 years ago

for let's say mydomain.com I have 2 subdomains : static.mydomain.com and api.mydomain.com.

After some authentication flow etc... I'm able to consume and display my PDF on the browser such as : 'api.mydomain.com/docs/myPDF12345'

However when hitting the url of the viewer (which is displayed successfully) http://api.mydomain.com/ViewerJS/#//api.mydomain.com/docs/myPDF12345 I'm unable to display it on the Viewer even though when I inspect the HTTP response it's shown downloaded :

Status Code:200 OK Remote Address:127.0.0.1:80 Response Headers view source Access-Control-Allow-Origin:* Connection:close Content-Disposition:inline; filename=CV-12.pdf Content-Length:182767 Content-Type:application/pdf; charset=UTF-8

I also tried to add the type=.pdf param at the end of my url, but nothing showed up on the viewer.

Any idea ?

MehdiFal commented 8 years ago

I can see on the logs after adding type=pdf : Found plugin by parameter type: pdf

but the name of the pdf displayed on the div #documentName is myPDF12345 like my url and not like file-name returned on the Http response header. Also the PDF is not displayed.

MehdiFal commented 8 years ago

Ok, so I updated my service to http://api.mydomain.com/ViewerJS/#//api.mydomain.com/docs/myPDF12345.pdf

The pdf name (the last portion of the url) is displayed but the pdf content is not even though downloaded.

SnakeSVx commented 8 years ago

This is probably related to the bug report I filed a while back: https://github.com/kogmbh/ViewerJS/issues/183

If the Content-Type head contains more then just application/pdf it won't detect it is a pdf and then won't even get the content.