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_PREFIX
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Deletes all files matching the givenQuery
.com.mongodb.client.gridfs.GridFSFindIterable
Returns all files matching the given query.com.mongodb.client.gridfs.model.GridFSFile
Returns a singleGridFSFile
matching the given query or null in case no file matches.getResource
(com.mongodb.client.gridfs.model.GridFSFile file) Returns theGridFsResource
for aGridFSFile
.getResource
(String filename) Returns theGridFsResource
with the given file name.getResources
(String filenamePattern) Returns allGridFsResource
s 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
store
(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
ObjectId
of theGridFSFile
just 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
ObjectId
of theGridFSFile
just 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
ObjectId
of theGridFSFile
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 theGridFSFile
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 theGridFSFile
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 theGridFSFile
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 theGridFSFile
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 theGridFSFile
just 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 currentlySort
criterias defined at theQuery
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 callingMongoIterable.into(java.util.Collection)
.- See Also:
-
findOne
Returns a singleGridFSFile
matching 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 theGridFsResource
with the given file name.- Specified by:
getResource
in interfaceResourceLoader
- Parameters:
filename
- must not be null.- Returns:
- the resource. Use
Resource.exists()
to check if the returnedGridFsResource
is actually present. - See Also:
-
getResource
Returns theGridFsResource
for aGridFSFile
.- Parameters:
file
- must not be null.- Returns:
- the resource for the file.
- Since:
- 2.1
-
getResources
Returns allGridFsResource
s matching the given file name pattern.- Specified by:
getResources
in interfaceResourcePatternResolver
- Parameters:
filenamePattern
- must not be null.- Returns:
- an empty array if none found.
- See Also:
-