public class GridFsTemplate extends Object implements GridFsOperations, ResourcePatternResolver
GridFsOperations implementation to store content into MongoDB GridFS.CLASSPATH_ALL_URL_PREFIXCLASSPATH_URL_PREFIX| Constructor and Description |
|---|
GridFsTemplate(MongoDatabaseFactory dbFactory,
MongoConverter converter)
|
GridFsTemplate(MongoDatabaseFactory dbFactory,
MongoConverter converter,
String bucket)
|
| Modifier and Type | Method and Description |
|---|---|
protected com.mongodb.client.gridfs.model.GridFSUploadOptions |
computeUploadOptionsFor(String contentType,
org.bson.Document metadata)
Compute the
GridFSUploadOptions to be used from the given contentType and metadata
Document. |
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. |
ClassLoader |
getClassLoader() |
protected org.bson.Document |
getMappedQuery(org.bson.Document query) |
GridFsResource |
getResource(com.mongodb.client.gridfs.model.GridFSFile file)
Returns the
GridFsResource for a GridFSFile. |
GridFsResource |
getResource(String location)
Returns the
GridFsResource with the given file name. |
GridFsResource[] |
getResources(String locationPattern)
Returns all
GridFsResources matching the given file name pattern. |
<T> T |
store(GridFsObject<T,InputStream> upload)
|
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.
|
protected org.bson.Document |
toDocument(Object value)
Convert a given value into a
Document. |
public GridFsTemplate(MongoDatabaseFactory dbFactory, MongoConverter converter)
dbFactory - must not be null.converter - must not be null.public GridFsTemplate(MongoDatabaseFactory dbFactory, MongoConverter converter, @Nullable String bucket)
dbFactory - must not be null.converter - must not be null.bucket - can be null.public org.bson.types.ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable Object metadata)
GridFsOperationsstore in interface GridFsOperationscontent - must not be null.filename - must not be null or empty.contentType - can be null.metadata - can be nullObjectId of the GridFSFile just created.public <T> T store(GridFsObject<T,InputStream> upload)
GridFsOperationsGridFsObject, 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. store in interface GridFsOperationsT - id type of the underlying GridFSFileupload - the GridFsObject (most likely a GridFsUpload) to be stored.GridFsObject.getFileId(), but never
null.public com.mongodb.client.gridfs.GridFSFindIterable find(Query query)
GridFsOperationsSort criterias defined at the
Query will not be regarded as MongoDB does not support ordering for GridFS file access.find in interface GridFsOperationsquery - must not be null.GridFSFindIterable to obtain results from. Eg. by calling
MongoIterable.into(java.util.Collection).public com.mongodb.client.gridfs.model.GridFSFile findOne(Query query)
GridFsOperationsGridFSFile matching the given query or null in
case no file matches.findOne in interface GridFsOperationsquery - must not be null.public void delete(Query query)
GridFsOperationsQuery.delete in interface GridFsOperationsquery - must not be null.public ClassLoader getClassLoader()
getClassLoader in interface ResourceLoaderpublic GridFsResource getResource(String location)
GridFsOperationsGridFsResource with the given file name.getResource in interface ResourceLoadergetResource in interface GridFsOperationslocation - must not be null.Resource.exists() to check if the returned
GridFsResource is actually present.ResourceLoader.getResource(String)public GridFsResource getResource(com.mongodb.client.gridfs.model.GridFSFile file)
GridFsOperationsGridFsResource for a GridFSFile.getResource in interface GridFsOperationsfile - must not be null.public GridFsResource[] getResources(String locationPattern)
GridFsOperationsGridFsResources matching the given file name pattern.getResources in interface ResourcePatternResolvergetResources in interface GridFsOperationslocationPattern - must not be null.ResourcePatternResolver.getResources(String)protected org.bson.Document getMappedQuery(org.bson.Document query)
query - pass the given query though a QueryMapper to apply type conversion.protected com.mongodb.client.gridfs.model.GridFSUploadOptions computeUploadOptionsFor(@Nullable String contentType, @Nullable org.bson.Document metadata)
GridFSUploadOptions to be used from the given contentType and metadata
Document.contentType - can be null.metadata - can be nullCopyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.