View Image from Directory

Asked

Viewed 146 times

1

I need to display an image in the application which is in the external directory of the application. I am using it as follows, however image is not displayed. It’s like the path is wrong.

public StreamedContent getImagem() {
        DefaultStreamedContent defaultStreamedContent = null;
        try {
            String caminhoArquivoCompleto = getCaminhoArquivoCompleto();
            File file = new File(caminhoArquivoCompleto);
            ByteArrayInputStream imagemStream = new ByteArrayInputStream(FileUtils.readFileToByteArray(file));
            defaultStreamedContent = new DefaultStreamedContent(imagemStream, "image/png");
        } catch (IOException io) {
            System.out.println(io.getCause());
        }
        return defaultStreamedContent;
    }


<p:graphicImage value="#{arquivo.imagem}" width="50" height="50" cache="false" />
  • Are you using Windows ? What returns in the method getCaminhoArquivoCompleto() ?

  • Use Win, Linux and Mac OS. public String getCaminhArchvoComplete() { if (Stringutils.isNotBlank(path)) { Return Propertiesutil.getValor(Constantesutil.CHAVES.UPLOAD) + path + name; } Return null; }

  • Debug there and tell the exact value that is in this method please. I have a suspicion but first I need to have this information

  • /User/Meuusuario/Downloads/uploadsistema It is an external directory application which I use a . properties to save when uploading. Detail that this same image is being used to generate a PDF report and in it print normally, my difficulty is in making display on the screen.

  • Look, I have a suspicion in the following: You using Windows it will not recognize this directory because windows uses a different method to access folders (" user\").

  • I’m using MAC for development. And I can’t display it anymore. This ai path is dynamic, actually it comes configured from a properties file. Being that the same one is used to upload images and files and Downloads that both work normal. my only problem is with displaying the image.

Show 1 more comment
No answers

Browser other questions tagged

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