Interface GridFsOperations

All Superinterfaces:
org.springframework.core.io.ResourceLoader, org.springframework.core.io.support.ResourcePatternResolver
All Known Implementing Classes:
GridFsTemplate

public interface GridFsOperations extends org.springframework.core.io.support.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
  • Field Summary

    Fields inherited from interface org.springframework.core.io.ResourceLoader

    CLASSPATH_URL_PREFIX

    Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver

    CLASSPATH_ALL_URL_PREFIX
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(Query query)
    Deletes all files matching the given Query.
    com.mongodb.client.gridfs.GridFSFindIterable
    find(Query query)
    Returns all files matching the given query.
    com.mongodb.client.gridfs.model.GridFSFile
    findOne(Query query)
    Returns a single GridFSFile matching the given query or null in case no file matches.
    getResource(com.mongodb.client.gridfs.model.GridFSFile file)
    Returns the GridFsResource for a GridFSFile.
    getResource(String filename)
    Returns the GridFsResource with the given file name.
    getResources(String filenamePattern)
    Returns all GridFsResources matching the given file name pattern.
    default org.bson.types.ObjectId
    store(InputStream content, Object metadata)
    Stores the given content into a file with the given name.
    default org.bson.types.ObjectId
    store(InputStream content, String filename)
    Stores the given content into a file with the given name.
    default org.bson.types.ObjectId
    store(InputStream content, String filename, Object metadata)
    Stores the given content into a file with the given name using the given metadata.
    default org.bson.types.ObjectId
    store(InputStream content, String filename, String contentType)
    Stores the given content into a file with the given name and content type.
    org.bson.types.ObjectId
    store(InputStream content, String filename, String contentType, Object metadata)
    Stores the given content into a file with the given name and content type using the given metadata.
    default org.bson.types.ObjectId
    store(InputStream content, String filename, String contentType, org.bson.Document metadata)
    Stores the given content into a file with the given name and content type using the given metadata.
    default org.bson.types.ObjectId
    store(InputStream content, String filename, org.bson.Document metadata)
    Stores the given content into a file with the given name using the given metadata.
    default org.bson.types.ObjectId
    store(InputStream content, org.bson.Document metadata)
    Stores the given content into a file with the given name.
    <T> T
    Stores the given GridFsObject, likely a GridFsUpload, into into a file with given name.

    Methods inherited from interface org.springframework.core.io.ResourceLoader

    getClassLoader
  • 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 org.springframework.core.io.ResourceLoader
      Parameters:
      filename - must not be null.
      Returns:
      the resource. Use Resource.exists() to check if the returned GridFsResource is actually present.
      See Also:
      • ResourceLoader.getResource(String)
    • 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 org.springframework.core.io.support.ResourcePatternResolver
      Parameters:
      filenamePattern - must not be null.
      Returns:
      an empty array if none found.
      See Also:
      • ResourcePatternResolver.getResources(String)