Interface GridFsOperations
- All Superinterfaces:
ResourceLoader,ResourcePatternResolver
- All Known Implementing Classes:
GridFsTemplate
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_PREFIXFields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX -
Method Summary
Modifier and TypeMethodDescriptionvoidDeletes all files matching the givenQuery.com.mongodb.client.gridfs.GridFSFindIterableReturns all files matching the given query.com.mongodb.client.gridfs.model.GridFSFileReturns a singleGridFSFilematching the given query or null in case no file matches.getResource(com.mongodb.client.gridfs.model.GridFSFile file) Returns theGridFsResourcefor aGridFSFile.getResource(String filename) Returns theGridFsResourcewith the given file name.getResources(String filenamePattern) Returns allGridFsResources matching the given file name pattern.default org.bson.types.ObjectIdstore(InputStream content, Object metadata) Stores the given content into a file with the given name.default org.bson.types.ObjectIdstore(InputStream content, String filename) Stores the given content into a file with the given name.default org.bson.types.ObjectIdstore(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.ObjectIdstore(InputStream content, String filename, String contentType) Stores the given content into a file with the given name and content type.org.bson.types.ObjectIdstore(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.ObjectIdstore(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.ObjectIdstore(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.ObjectIdstore(InputStream content, org.bson.Document metadata) Stores the given content into a file with the given name.<T> Tstore(GridFsObject<T, InputStream> upload) Methods inherited from interface org.springframework.core.io.ResourceLoader
getClassLoader
-
Method Details
-
store
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
ObjectIdof theGridFSFilejust created.
-
store
Stores the given content into a file with the given name.- Parameters:
content- must not be null.metadata- can be null.- Returns:
- the
ObjectIdof theGridFSFilejust created.
-
store
Stores the given content into a file with the given name.- Parameters:
content- must not be null.metadata- can be null.- Returns:
- the
ObjectIdof theGridFSFilejust 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
ObjectIdof theGridFSFilejust 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
ObjectIdof theGridFSFilejust 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
ObjectIdof theGridFSFilejust 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
ObjectIdof theGridFSFilejust 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
ObjectIdof theGridFSFilejust created.
-
store
Stores the givenGridFsObject, likely aGridFsUpload, into into a file with givenname. If theGridFsObject.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 underlyingGridFSFile- Parameters:
upload- theGridFsObject(most likely aGridFsUpload) 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
Returns all files matching the given query. Note, that currentlySortcriterias defined at theQuerywill not be regarded as MongoDB does not support ordering for GridFS file access.- Parameters:
query- must not be null.- Returns:
GridFSFindIterableto obtain results from. Eg. by callingMongoIterable.into(java.util.Collection).- See Also:
-
findOne
Returns a singleGridFSFilematching the given query or null in case no file matches.- Parameters:
query- must not be null.- Returns:
- can be null.
-
delete
Deletes all files matching the givenQuery.- Parameters:
query- must not be null.
-
getResource
Returns theGridFsResourcewith the given file name.- Specified by:
getResourcein interfaceResourceLoader- Parameters:
filename- must not be null.- Returns:
- the resource. Use
Resource.exists()to check if the returnedGridFsResourceis actually present. - See Also:
-
getResource
Returns theGridFsResourcefor aGridFSFile.- Parameters:
file- must not be null.- Returns:
- the resource for the file.
- Since:
- 2.1
-
getResources
Returns allGridFsResources matching the given file name pattern.- Specified by:
getResourcesin interfaceResourcePatternResolver- Parameters:
filenamePattern- must not be null.- Returns:
- an empty array if none found.
- See Also:
-