Reputation: 6873
<p:media value="C:/Users/xyz/Desktop/sample.pdf" width="100%" height="600px">
</p:media>
I'm using this code to load the PDF placed on my desktop but it is not loading the PDF from that place.I searched a lot but unable to find the reason.So from JSF experts I want to know that is it possible to load a file/pdf/image (any resource) from outside the project's folder using primefaces media tag? If yes then How?
Note: I am able to load this pdf if i placed it in my project's folder.but I want to load it from outside.
Thanks
Upvotes: 1
Views: 3721
Reputation: 1108692
The value must point to a valid URL, not to a local disk file system path. It's the webbrowser who has got to download the PDF from that URL. It's not the webserver who has got to auto-include the PDF in the HTML output somehow as you seemed to expect.
You can't expect from every webpage visitor that they have exactly that PDF file in exactly that location on their own local disk file system. Let alone that they also run Windows.
Easist way would be to move that PDF into the public web content folder (there where you also put your JSF pages in) and reference it as follows instead
<p:media value="/sample.pdf" width="100%" height="600px" />
Assuming that the JSF page in question is served through http://example.com/context/page.xhtml, then the webbrowser will download the PDF by http://example.com/context/sample.pdf (and you need to make sure that it's also individually available by exactly that URL).
A different alternative, if you don't want to put PDF files in your webapp, but elsewhere, is to add exactly that disk file system location as "virtual host" to the server configuration so that it's available by an URL. You can find some hints here: How to show the server path image to PrimeFaces p:graphicImage?
Upvotes: 2