Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • Okay, thanks. I've succeeded in saving the image into a specific folder inside the app directory (actualy it's in src/main/resources/META-INF/resources/photos). I read on that link that it was the place for static images. But I can't create an Image out of that path now. It's like it doesn't know where to look for the image. I can put some screens about the path and how I create the image if it helps you understand it. I'm sorry if my english isn't great. Commented May 6, 2021 at 7:01
  • 1
    During project compilation src/main/resources is copied to the target/classes folder (in this case to target/classes/META-INF/resources/photos) so during execution you won't get the uploaded file as a resource through there. The file should be stored somewhere else on the file system and loaded from there and made into a StreamResource for serving during execution. Commented May 6, 2021 at 9:12
  • Okay, it's a bit blurry for me, would it be possible to have an example using the StreamResource thing? Because, from what I understand, I can't create an image from the copied File because it's not stored at a correct place. But where and how should I store it? Commented May 6, 2021 at 11:07
  • The target file could be anywhere on the disk and then you can read it to a inputStream File imageFile = new File("my/downloaded/file.jgp"); -> InputStream targetStream = FileUtils.openInputStream(imageFile); that is then used for the StreamResource Commented May 6, 2021 at 12:17
  • 1
    Okay so if I understand correctly: - When the user uploads an image, I copy the file to a directory /home/user/photos as an example. - I store the path of the File in my Database - When he goes to the view where I need to display the image: I create an InputStream with the image, to then use StreamResource to display the content Is that it? And if you know it, could you explain to me how to use that StreamResource ? Thanks by the way. Commented May 6, 2021 at 12:46