0

I have String path that I'll use to show image on header, I take the path from database that return a String filename for image, then the image are in "D:\Job\Potapota\images\(filename)". I already did the String path from db that I initialize on a.setValue(dao.getLogos());. It means if i want to get the filename only like a.getValue().

so this is my html page

<p:graphicImage value="#{fileUploadViewBean.imageStatus}" library="atlantis-layout"/>

then the class FileUploadViewBean is this

public class FileUploadViewBean extends CommonBean {

private StreamedContent imageStatus;
public void init() throws IOException{
    getLogo();
}

public StreamedContent getImageStatus() {
    return imageStatus;
}

public void setImageStatus(StreamedContent imageStatus) {
    this.imageStatus = imageStatus;
}

public void getLogo() throws IOException {
    SystemMaster a = new SystemMaster();
    FacesContext context = FacesContext.getCurrentInstance();
    try {
        a.setValue(dao.getLogos());
    } catch (Exception e) {
        setMessage(new FacesMessage(e.getMessage()));
        getMessage().setSeverity(FacesMessage.SEVERITY_FATAL);
        FacesContext.getCurrentInstance().addMessage(null, getMessage());
    }
    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        // So, we're rendering the view. Return a stub StreamedContent so
        // that it will generate right URL.
        imageStatus = new DefaultStreamedContent();
    } else {
        // So, browser is requesting the image. Return a real
        // StreamedContent with the image bytes.
        String filename = 
context.getExternalContext().getRequestParameterMap().get(a.getValue());
        imageStatus = new DefaultStreamedContent(
                new FileInputStream(new File("D:\\Job\\Potapota\\images\\", 
        filename)), "image/jpeg");
    }
}

but then the image doesn't show up, can somebody know what is the true code for this.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Andre
  • 1
  • 5
  • In the duplicate, just substitute "database" with "disk file system". – BalusC Oct 04 '17 at 06:11
  • i think it is different cause mine using String path from db, not an Image datatype, so this method should be use to take an image from the path – Andre Oct 04 '17 at 07:22
  • No Andre, it's not different. As said, in the duplicate, just substitute "database" with "disk file system". In other words, just let `student.getImage()` return `new FileInputStream(yourPath)` instead of `resultSet.getInputStream(dbColumn)`. The duplicate also very clearly states that you should absolutely not hold `StreamedContent` as a bean property but instead create it in the `getImageStatus()`. The problem is handling the `StreamedContent` itself, not the disk file system or database or wherever you get the image from. That's completely irrelevant. – BalusC Oct 04 '17 at 08:23
  • thxx it works , i appreciate ur help – Andre Oct 10 '17 at 03:41

0 Answers0