createInputStream method in InputStreamFactory returns null?

Hi, I am making application which uploads image files, saves them in resources and next read them and show in Scroller. Files are saving properly, but they don’t appear. What is surprising, when I rebuilded the project, everything started to work properly (files saved before rebuild are displayed), but when I add a new image, it doesn’t appear (after page reloading it still doesn’t work) even though in both cases the same function is invoked…
I got such exception (more in the attachment):


Here the problematic code fragment:
    public MessageListItem(List<Attachment> attachments, String text, Instant time, String userName, AbstractStreamResource avatarResource) {
        this(text, time, userName, avatarResource);

        for (Attachment attachment : attachments) {
            StreamResource streamResource = new StreamResource(attachment.toString(), attachment.getImage());
            Image contentImage = new Image(streamResource, "alt");
I am getting file from resources, creating InputStreamFactory by lambda expression, and next creating Attachement object.
public class Attachment {
    private InputStreamFactory image;
    private String mime;

What do you mean with “saves them in resources”?

I mean spring project resources

That can’t work. Are you expecting to write in your production jar/war?

I do the same thing with user avatars and it works, I’m also getting InputStream → creating StreamResource and creating avatar with this… Why it can’t work now?

So you are telling me you have an application somewhere running where you write in the running application’s jar and losing all uploaded avatars once a new version is deployed? :sweat_smile:

Oh… OH… luckily it’s a student project and no one will use that :laughing:

So, what do you suggest?

Adding the files to the filesystem or another storage system like database; but for a student project - the filesystem next to the app would probably the easiest you can use File or Path Resources; those can access the files and get you the input streams you need (always)

Okay thx, I still have a lot to learn :sweat_smile: