webodf / ViewerJS

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

dynamic content and type detection problem with URL parameters #46

Closed drlivingston closed 9 years ago

drlivingston commented 10 years ago

If I have a dynamically generated / custom served PDF (because I have to use URLs that expire and that verify security settings in the session before serving content) I have issues with the type detection:

This works as expected:

http://localhost:8080/Viewer.js/index.html#/test/pdf/demodoc.pdf

This does not work:

http://localhost:8080/Viewer.js/index.html#/test/pdf/demodoc.pdf?foo=bar

This hack with a parameter I don't look at forced on the end does:

http://localhost:8080/Viewer.js/index.html#/test/pdf/demodoc.pdf?foo=bar&type=.pdf

I think the problem is here:

function loadDocument(documentUrl) {
    "use strict";

    if (documentUrl) {
        var extension = documentUrl.split('.').pop(),

this function assumes that there are no parameters

The following might fix this:

function loadDocument(documentUrl) {
    "use strict";

    if (documentUrl) {
        var extension = documentUrl.split('?')[0].split('.').pop(),
drlivingston commented 10 years ago

Ideally I would think the tools should observe the content-type header if provided, wouldn't that be best?

kossebau commented 9 years ago

ViewerJS 0.5.5 got released today, which features an initial HEAD request to learn about the content type, and also as fallback dropping the arguments from the passed document url, as proposed also above. Additionally the type can be set by passing an argument to ViewerJS itself, e.g. like /ViewerJS/index.html?type=pdf#/test/pdf/demodoc.pdf?foo=bar. These approaches should enable to solve the problem reported in this issue, thus closing it now.