[Cubicweb] Preview with ViewerJS in CW

St├ęphane Bugat stephane.bugat at free.fr
Thu Mar 31 19:23:51 CEST 2016


Hi Christophe

> 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

Okay, thanks a lot...
The built URL using your method looks like the following: http://myserver:8080/data/0a6bfcf4ea4e36b05a5bacb5e843de69/ViewerJS/#../file/1487/raw/foo.pdf

Tried it but the preview failed with an error: "une erreur est survenue. Cette action est interdite. (...)"
(sorry for the french...).

Any idea?



More information about the Cubicweb mailing list