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()
?– Roknauta
Use Win, Linux and Mac OS. public String getCaminhArchvoComplete() { if (Stringutils.isNotBlank(path)) { Return Propertiesutil.getValor(Constantesutil.CHAVES.UPLOAD) + path + name; } Return null; }
– Jeremias Santos
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
– Roknauta
/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.
– Jeremias Santos
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\").
– Roknauta
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.
– Jeremias Santos