Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentRepository cannot persistent content #517

Closed
ostmond opened this issue Mar 26, 2021 · 2 comments
Closed

ContentRepository cannot persistent content #517

ostmond opened this issue Mar 26, 2021 · 2 comments

Comments

@ostmond
Copy link

ostmond commented Mar 26, 2021

Hi,

I am using MongoDB to save the file meta information and use content-fs-spring-boot-starter 1.2.1 to persist the FileStream like this:

contentRepository.setContent(meta, Files.newInputStream('/tmp/test.mp3'));
metaRepository.save(meta);

It was OK when I played the music on a GET-endpoint after I persisted the meta. However, after I restarted my Spring-Boot application and tried to play the music again, I got the Exception 'InputStream must not be null' when getContent was called. It seemed that the content had not been persisted really.

Do you have any idea? Thanks!

@paulcwarren
Copy link
Owner

paulcwarren commented Mar 26, 2021

Sounds like you are not setting a permanent root for the filesystem content store? By default the spring boot starter will choose a new temporary folder in your tmpdir everytime it starts up - giving an experience a bit like using H2 or HSQLDB. Usually fine for testing.

You need to override that behavior with a bean to sets a permanent root. Or, since you're using Mongo, use Mongo's GridFS?). The docs example is also using a temp dir which probably isn't the best example but hopefully you get the point. You need to set a permanent root; e.g. /data/mystore.

@ostmond
Copy link
Author

ostmond commented Mar 26, 2021

Thank you very much! I set up the file system root, and It works now as you suggested.

@Configuration
@EnableFilesystemStores
public class ContentConfig {
    @Value("${file.upload.dir}")
    private String uploadDir;

    @Bean
    File filesystemRoot() {
        try {
            return Files.createDirectory(Paths.get(uploadDir)).toFile();
        } catch (FileAlreadyExistsException faee) {
          return new File(uploadDir);
        } catch (IOException ioe) {}

        return null;
    }

    @Bean
    FileSystemResourceLoader fileSystemResourceLoader() {
        return new FileSystemResourceLoader(filesystemRoot().getAbsolutePath());
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants