Error 500 when trying to read a PDF

Asked

Viewed 41 times

0

The view is like this:

<p:media cache="false" value="#{documents.readPDF()}" width="640px" height="480px" player="pdf" />

No bean is like this:

public StreamedContent readPDF() {
        FileModel pdfModel = getDocumentPDF();
        InputStream stream = new ByteArrayInputStream(pdfModel.getBytes());
        return new DefaultStreamedContent(stream, "application/pdf", pdfModel.getFileName());
    }

But I get a mistake 500 http://localhost:8080/Aerion/javax.faces.Resource/dynamiccontent.properties.xhtml;/Testdocument%20of%20Web.pdf? ln=primefaces&v=6.1&pfdrid=fc3f2eba005bcd903c7eec3459182335&pfdrt=sc&pfdrid_c=false&uid=f3cf7c99-d4bf-4886-b3ea-d1b8bf07cf48

1 answer

0

Friend, you have posted a local URL that we cannot open, if you would kindly present a screen print with the error. Please also review the file permissions.

I don’t know much about Java, but I tried to structure the code differently, I could try?

If I’m talking nonsense, I’m sorry.

public StreamedContent readPDF() {
        try {
        FileModel pdfModel = getDocumentPDF();
        InputStream stream;
        stream = new ByteArrayInputStream(pdfModel.getBytes());
        StreamedContent file = new DefaultStreamedContent(stream, stream, "application/pdf", pdfModel.getFileName());
        return file;
    } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.