What I intend to do: I'd like to use multiple ContentStores in the same system: one for freshly uploaded files (filesystem), one for (long term) archiving (AWS S3 or maybe GCS).
What I tried (and what actually does work):
Extended class
Fileby another attributeprivate String contentStoreName;Creating two
ContentStores like described here: Spring-Content: Moving files from content store to another content storeExtending
gettingstarted.FileContentController.setContent(Long, MultipartFile)by setting an identifier for the usedContentStore:f.get().setContentStoreName("regular");Getting the content in dependence of the stored
contentStoreName:InputStream input; if (Objects.equals(f.get().getContentStoreName(), "archive")) { input = archiveContentStore.getContent(f.get()); } else { input = regularContentStore.getContent(f.get()); }Changing the
contentStoreNamewhen moving from oneContentStoreto another:Resource resource = regularContentStore.getResource(fileEntity.get()); archiveContentStore.setContent(fileEntity.get(), resource); fileEntity.get().setContentStoreName("archive"); filesRepo.save(fileEntity.get());
The smell about this: Despite this code works, I guess it's not the intended way, because Spring-content usually does a lot with annotations and some magic in the background. But I can't find an annotation for an identifier / name for the ContentStore.
Question: Is there a more intended way of doing this in Spring-Content?