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 ResourceLoader
CLASSPATH_URL_PREFIXFields inherited from interface ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX -
Method Summary
Modifier and TypeMethodDescriptionvoidDeletes all files matching the givenQuery.Returns all files matching the given query.Returns a singleGridFSFilematching the given query or null in case no file matches.getResource(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 ObjectIdstore(InputStream content, @Nullable Object metadata) Stores the given content into a file with the given name.default ObjectIdStores the given content into a file with the given name using the given metadata.default ObjectIdStores the given content into a file with the given name and content type.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.default ObjectIdstore(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable Document metadata) Stores the given content into a file with the given name and content type using the given metadata.default ObjectIdStores the given content into a file with the given name using the given metadata.default ObjectIdstore(InputStream content, String filename) Stores the given content into a file with the given name.default ObjectIdstore(InputStream content, @Nullable Document metadata) Stores the given content into a file with the given name.<T> Tstore(GridFsObject<T, InputStream> upload) Methods inherited from interface 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 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
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
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
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 ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable 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
-
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:
-