2
votes
<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

1
hmmmm are you sure the server does not implement the CORS (cross origin resource sharing), more over while loading resources from the cross domain you can always use the iframes...Dakait
can you please explain what do you mean exactly by "outside the project folder" is that folder located on the same web server where your project is deployed?Dakait
ofcourse, folder is placed on same web server.Let say , My application is deployed on Glassfish server then on the same server , I want to load this PDF from D: drive.By "outside the project's folder" I mean that The PDF file is not placed in resource folder of projectFreak
where is the root of the glassfish pointing toDakait

1 Answers

2
votes

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?