[Cubicweb] Preview with ViewerJS in CW

Christophe de Vienne christophe at unlish.com
Wed Mar 30 09:27:46 CEST 2016

Hello Stéphane,

>From what I understand you do not need an actual path on the server,
only the webpath from the URL.

You can use the download_url()[1] function of the IDownloadable
interface to get one, but you will have to remove the base_url() from it
because download_url() returns an absolute URL.

For example:

  f = find('File', ...).one()
  url = f.cw_adapt_to('IDownloadable').download_url()
  path = url.rstrip(_cw.base_url())

Then you just need to prepend the ViewerJS url and the needed '..' to
"go back to the top folder" (quoting ViewerJS doc) :

  href = _cw.data_url('ViewerJS') + '#..' + path

Hope this help,



Le 29/03/2016 07:01, Stéphane Bugat a écrit :
> Hi World!
> Back (and glad to be back) in CW community for another project!
> This today's issue: how to preview some files (like PDFs) in a CW view
> using ViewerJS?
> As far as I understood: the usual way to use ViewerJS is to install it
> on the server side, and add "ViewerJS/../#" to the base of the URL of
> the file that has to be previewed.
> However, in CW, downloadable URL's for files do not correspond to an
> actual "place" on the server, and this seems to fail with a kind of "bad
> resource location".
> So my question is: is there a 'simple' other way to deal with it? I saw
> that there is for instance a cache mechanism for thumbnail images that
> could be templated for that... But I don't know if this is the right way
> to do it, and moreover I'm still wondering if this does not create
> permission issues?
> Stephane
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> https://lists.cubicweb.org/mailman/listinfo/cubicweb

Christophe de Vienne
Co-fondateur http://unli.sh

More information about the Cubicweb mailing list