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(MongoDbFactory dbFactory,
MongoConverter converter)
|
GridFsTemplate(MongoDbFactory 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. |
org.bson.types.ObjectId |
store(InputStream content,
org.bson.Document metadata)
Stores the given content into a file with the given name.
|
org.bson.types.ObjectId |
store(InputStream content,
Object metadata)
Stores the given content into a file with the given name.
|
org.bson.types.ObjectId |
store(InputStream content,
String filename)
Stores the given content into a file with the given name.
|
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.
|
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.
|
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,
org.bson.Document metadata)
Stores the given content into a file with the given name and content type using the given metadata.
|
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(MongoDbFactory dbFactory, MongoConverter converter)
dbFactory - must not be null.converter - must not be null.public GridFsTemplate(MongoDbFactory dbFactory, MongoConverter converter, @Nullable String bucket)
dbFactory - must not be null.converter - must not be null.bucket - public org.bson.types.ObjectId store(InputStream content, String filename)
GridFsOperationsstore in interface GridFsOperationscontent - must not be null.filename - must not be null or empty.ObjectId of the GridFSFile just created.public org.bson.types.ObjectId store(InputStream content, @Nullable Object metadata)
GridFsOperationsstore in interface GridFsOperationscontent - must not be null.metadata - can be null.ObjectId of the GridFSFile just created.public org.bson.types.ObjectId store(InputStream content, @Nullable org.bson.Document metadata)
GridFsOperationsstore in interface GridFsOperationscontent - must not be null.metadata - can be null.ObjectId of the GridFSFile just created.public org.bson.types.ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType)
GridFsOperationsstore in interface GridFsOperationscontent - must not be null.filename - must not be null or empty.contentType - can be null.ObjectId of the GridFSFile just created.public org.bson.types.ObjectId store(InputStream content, @Nullable String filename, @Nullable Object metadata)
GridFsOperationsstore in interface GridFsOperationscontent - must not be null.filename - can be null or empty.metadata - can be null.ObjectId of the GridFSFile just created.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 org.bson.types.ObjectId store(InputStream content, @Nullable String filename, @Nullable org.bson.Document metadata)
GridFsOperationsstore in interface GridFsOperationscontent - must not be null.filename - must not be null or empty.metadata - can be null.ObjectId of the GridFSFile just created.public org.bson.types.ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable org.bson.Document metadata)
GridFsOperationsstore in interface GridFsOperationscontent - must not be null.filename - must not be null or empty.contentType - can be null.metadata - can be null.ObjectId of the GridFSFile just created.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–2020 Pivotal Software, Inc.. All rights reserved.