Image not loaded with Stream Resource (Vaadin 23)

Hi, im trying to update an Image component through StreamResouce. but i have the problem. the Image is not displayed from StreamResource. (i’ve checked the directory path and its correct).

this is how i use the code

and for the setImageSource

the image path format value looks like this
“D:\folder1\filename.png”

EDIT : I tried to add alot of error message if my code is error or not, but i dont get any error Notification or error from stackTrace

With this I can not exactly debug what the issue is, but you might want to use a ByteArrayInputStream and read the file using Files.readAllBytes(imageFilePath).

So instead of the return new FileInputStream(file) have it as return new ByteArrayInputStream(Files.readAllBytes(imageFilePath)); as that will not leave the FileInputStream open as your current code does.

For just showing images I would rather handle them as static or class resources see Images & Icons | Application Basics | Flow | Vaadin Docs

1 Like

Hi, thank you for reply.

So, i tried using new Image Component (the code i show it to you is being used by Uploader. but i dont think i can’t use 1 Image Component with 2 different Source. first is from byte64 data, and the second one is from StreamResource. ) and it working. i have no idea why image component can’t get source from different source type.

anyway. noow im using 2 image component (1 from Byte64 and another one using StreamResource). but i’ll try your advice later. thank you

1 Like