Class FilesystemMediaStorage

java.lang.Object
com.onec.ui.media.FilesystemMediaStorage
All Implemented Interfaces:
MediaStorage

public class FilesystemMediaStorage extends Object implements MediaStorage
The default MediaStorage: streams uploads to a directory tree on disk and serves them back through GET /api/media/{key}. Keys are date-sharded (yyyy/MM/<uuid>.<ext>) so a single directory never accumulates unbounded entries and the stored name leaks nothing about the original. Suitable for single-node deployments and development; multi-node setups should swap in an object-store backend by exposing their own MediaStorage bean.
  • Constructor Details

    • FilesystemMediaStorage

      public FilesystemMediaStorage(Path root, String publicBasePath)
  • Method Details

    • store

      public StoredMedia store(InputStream content, String filename, String contentType, long size) throws IOException
      Description copied from interface: MediaStorage
      Persist an uploaded binary and return a reference to it.
      Specified by:
      store in interface MediaStorage
      Parameters:
      content - the file bytes; the implementation reads (and the caller closes) this stream
      filename - the original client filename, already sanitized to a bare name (may be blank)
      contentType - the validated content type (never null/blank)
      size - the declared size in bytes, or -1 if the client didn't report one
      Throws:
      IOException
    • load

      public Optional<LoadedMedia> load(String key)
      Description copied from interface: MediaStorage
      Read a previously stored binary back for serving by GET /api/media/{key}. The default returns empty, which makes that endpoint answer 404 — appropriate for backends whose url already points at a directly reachable object-store address.
      Specified by:
      load in interface MediaStorage
      Parameters:
      key - the key produced by a prior MediaStorage.store(java.io.InputStream, java.lang.String, java.lang.String, long)