Image Component FileResource [Vaadin 10]

We would like to display images from a directory / File Share (FileResource).

[In Vaadin 8]

Image image = new Image ();
FileResource resource = new FileResource (“C: \ temp”);
image.setSource (resource);

In Vaadin 10 we could not find a similar function.
The component “Image” only allows access to a URL and the “frontend” folder.

how can we solve this problem?

Maybe this could help you:

 public static Image generateImage(String imagePath) throws IOException {
        return generateImage(getBytesFromFile(imagePath));
    }
	
 public static byte[] getBytesFromFile(String imagePath) throws IOException {
        File file = new File(imagePath);
        return Files.readAllBytes(file.toPath());
    }	
	
 public static Image generateImage(byte[] bytes) {
        Objects.requireNonNull(bytes)
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        StreamResource sr = new StreamResource("user", () -> bis);
        Image image = new Image(sr, "image");
        return image;
    }

Diego Sanz Villafruela:
Maybe this could help you:

 public static Image generateImage(String imagePath) throws IOException {
        return generateImage(getBytesFromFile(imagePath));
    }
	
 public static byte[] getBytesFromFile(String imagePath) throws IOException {
        File file = new File(imagePath);
        return Files.readAllBytes(file.toPath());
    }	
	
 public static Image generateImage(byte[] bytes) {
        Objects.requireNonNull(bytes)
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        StreamResource sr = new StreamResource("user", () -> bis);
        Image image = new Image(sr, "image");
        return image;
    }

this work well for me.
Thanks’ Very Much