Add metadata to files
FileReferenceProperties
Before a FileReference
get’s persisted a FileReferenceCreationEvent
is emitted that can be used to modify the newly created
file. It provides a way to configure additional properties through FileReferenceProperties
. Theses properties can be used to store
metadata about the file that was uploaded.
Add FileReferenceProperties to a FileReference
@Configuration
@RequiredArgsConstructor
public class CustomFileRepositoryConfiguration {
private final FileReferencePropertiesService fileReferencePropertiesService;
@EventListener
public void fileReferenceSaved(FileReferenceCreationEvent fileReferenceCreationEvent) {
FileReferenceProperties properties = fileReferenceCreationEvent.getFileReferenceProperties();
properties.put("customProperty", "value");
}
}
The FileReferenceService
will save the FileReferenceProperties
together with the FileReference
after
all events are handled.