Interface GridFsOperations

All Superinterfaces:
ResourceLoader, ResourcePatternResolver
All Known Implementing Classes:
GridFsTemplate

public interface GridFsOperations extends ResourcePatternResolver
Collection of operations to store and read files from MongoDB GridFS.
Author:
Oliver Gierke, Philipp Schneider, Thomas Darimont, Martin Baumgartner, Christoph Strobl, Hartmut Lang
  • Method Details

    • store

      default org.bson.types.ObjectId store(InputStream content, String filename)
      Stores the given content into a file with the given name.
      Parameters:
      content - must not be null.
      filename - must not be null or empty.
      Returns:
      the ObjectId of the GridFSFile just created.
    • store

      default org.bson.types.ObjectId store(InputStream content, @Nullable Object metadata)
      Stores the given content into a file with the given name.
      Parameters:
      content - must not be null.
      metadata - can be null.
      Returns:
      the ObjectId of the GridFSFile just created.
    • store

      default org.bson.types.ObjectId store(InputStream content, @Nullable org.bson.Document metadata)
      Stores the given content into a file with the given name.
      Parameters:
      content - must not be null.
      metadata - can be null.
      Returns:
      the ObjectId of the GridFSFile just created.
    • store

      default org.bson.types.ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType)
      Stores the given content into a file with the given name and content type.
      Parameters:
      content - must not be null.
      filename - must not be null or empty.
      contentType - can be null.
      Returns:
      the ObjectId of the GridFSFile just created.
    • store

      default org.bson.types.ObjectId store(InputStream content, @Nullable String filename, @Nullable Object metadata)
      Stores the given content into a file with the given name using the given metadata. The metadata object will be marshalled before writing.
      Parameters:
      content - must not be null.
      filename - can be null or empty.
      metadata - can be null.
      Returns:
      the ObjectId of the GridFSFile just created.
    • store

      org.bson.types.ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable Object metadata)
      Stores the given content into a file with the given name and content type using the given metadata. The metadata object will be marshalled before writing.
      Parameters:
      content - must not be null.
      filename - must not be null or empty.
      contentType - can be null.
      metadata - can be null
      Returns:
      the ObjectId of the GridFSFile just created.
    • store

      default org.bson.types.ObjectId store(InputStream content, @Nullable String filename, @Nullable org.bson.Document metadata)
      Stores the given content into a file with the given name using the given metadata.
      Parameters:
      content - must not be null.
      filename - must not be null or empty.
      metadata - can be null.
      Returns:
      the ObjectId of the GridFSFile just created.
    • store

      default org.bson.types.ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable org.bson.Document metadata)
      Stores the given content into a file with the given name and content type using the given metadata.
      Parameters:
      content - must not be null.
      filename - must not be null or empty.
      contentType - can be null. If not empty, may override content type within metadata.
      metadata - can be null.
      Returns:
      the ObjectId of the GridFSFile just created.
    • store

      <T> T store(GridFsObject<T,InputStream> upload)
      Stores the given GridFsObject, likely a GridFsUpload, into into a file with given name. If the GridFsObject.getFileId() is set, the file will be stored with that id, otherwise the server auto creates a new id.
      Type Parameters:
      T - id type of the underlying GridFSFile
      Parameters:
      upload - the GridFsObject (most likely a GridFsUpload) to be stored.
      Returns:
      the id of the stored file. Either an auto created value or GridFsObject.getFileId(), but never null.
      Since:
      3.0
    • find

      com.mongodb.client.gridfs.GridFSFindIterable find(Query query)
      Returns all files matching the given query. Note, that currently Sort criterias defined at the Query will not be regarded as MongoDB does not support ordering for GridFS file access.
      Parameters:
      query - must not be null.
      Returns:
      GridFSFindIterable to obtain results from. Eg. by calling MongoIterable.into(java.util.Collection).
      See Also:
    • findOne

      @Nullable com.mongodb.client.gridfs.model.GridFSFile findOne(Query query)
      Returns a single GridFSFile matching the given query or null in case no file matches.
      Parameters:
      query - must not be null.
      Returns:
      can be null.
    • delete

      void delete(Query query)
      Deletes all files matching the given Query.
      Parameters:
      query - must not be null.
    • getResource

      GridFsResource getResource(String filename)
      Returns the GridFsResource with the given file name.
      Specified by:
      getResource in interface ResourceLoader
      Parameters:
      filename - must not be null.
      Returns:
      the resource. Use Resource.exists() to check if the returned GridFsResource is actually present.
      See Also:
    • getResource

      GridFsResource getResource(com.mongodb.client.gridfs.model.GridFSFile file)
      Returns the GridFsResource for a GridFSFile.
      Parameters:
      file - must not be null.
      Returns:
      the resource for the file.
      Since:
      2.1
    • getResources

      GridFsResource[] getResources(String filenamePattern)
      Returns all GridFsResources matching the given file name pattern.
      Specified by:
      getResources in interface ResourcePatternResolver
      Parameters:
      filenamePattern - must not be null.
      Returns:
      an empty array if none found.
      See Also: