@ThreadSafe
public interface GridFSBucket
Modifier and Type | Method and Description |
---|---|
org.reactivestreams.Publisher<Success> |
delete(org.bson.BsonValue id)
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
org.reactivestreams.Publisher<Success> |
delete(org.bson.types.ObjectId id)
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
org.reactivestreams.Publisher<Long> |
downloadToStream(org.bson.BsonValue id,
AsyncOutputStream destination)
Downloads the contents of the stored file specified by
id and writes the contents to the destination
AsyncOutputStream. |
org.reactivestreams.Publisher<Long> |
downloadToStream(org.bson.types.ObjectId id,
AsyncOutputStream destination)
Downloads the contents of the stored file specified by
id and writes the contents to the destination
AsyncOutputStream. |
org.reactivestreams.Publisher<Long> |
downloadToStream(String filename,
AsyncOutputStream destination)
Downloads the contents of the latest version of the stored file specified by
filename and writes the contents to
the destination Stream. |
org.reactivestreams.Publisher<Long> |
downloadToStream(String filename,
AsyncOutputStream destination,
com.mongodb.client.gridfs.model.GridFSDownloadOptions options)
Downloads the contents of the stored file specified by
filename and by the revision in options and writes the
contents to the destination Stream. |
org.reactivestreams.Publisher<Success> |
drop()
Drops the data associated with this bucket from the database.
|
GridFSFindPublisher |
find()
Finds all documents in the files collection.
|
GridFSFindPublisher |
find(org.bson.conversions.Bson filter)
Finds all documents in the collection that match the filter.
|
String |
getBucketName()
The bucket name.
|
int |
getChunkSizeBytes()
Sets the chunk size in bytes.
|
com.mongodb.ReadConcern |
getReadConcern()
Get the read concern for the GridFSBucket.
|
com.mongodb.ReadPreference |
getReadPreference()
Get the read preference for the GridFSBucket.
|
com.mongodb.WriteConcern |
getWriteConcern()
Get the write concern for the GridFSBucket.
|
GridFSDownloadStream |
openDownloadStream(org.bson.BsonValue id)
Opens a AsyncInputStream from which the application can read the contents of the stored file specified by
id . |
GridFSDownloadStream |
openDownloadStream(org.bson.types.ObjectId id)
Opens a AsyncInputStream from which the application can read the contents of the stored file specified by
id . |
GridFSDownloadStream |
openDownloadStream(String filename)
Opens a Stream from which the application can read the contents of the latest version of the stored file specified by the
filename . |
GridFSDownloadStream |
openDownloadStream(String filename,
com.mongodb.client.gridfs.model.GridFSDownloadOptions options)
Opens a Stream from which the application can read the contents of the stored file specified by
filename and the revision
in options . |
GridFSUploadStream |
openUploadStream(org.bson.BsonValue id,
String filename)
Opens a AsyncOutputStream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(org.bson.BsonValue id,
String filename,
com.mongodb.client.gridfs.model.GridFSUploadOptions options)
Opens a AsyncOutputStream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(String filename)
Opens a AsyncOutputStream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(String filename,
com.mongodb.client.gridfs.model.GridFSUploadOptions options)
Opens a AsyncOutputStream that the application can write the contents of the file to.
|
org.reactivestreams.Publisher<Success> |
rename(org.bson.BsonValue id,
String newFilename)
Renames the stored file with the specified
id . |
org.reactivestreams.Publisher<Success> |
rename(org.bson.types.ObjectId id,
String newFilename)
Renames the stored file with the specified
id . |
org.reactivestreams.Publisher<Success> |
uploadFromStream(org.bson.BsonValue id,
String filename,
AsyncInputStream source)
Uploads the contents of the given
AsyncInputStream to a GridFS bucket. |
org.reactivestreams.Publisher<Success> |
uploadFromStream(org.bson.BsonValue id,
String filename,
AsyncInputStream source,
com.mongodb.client.gridfs.model.GridFSUploadOptions options)
Uploads the contents of the given
AsyncInputStream to a GridFS bucket. |
org.reactivestreams.Publisher<org.bson.types.ObjectId> |
uploadFromStream(String filename,
AsyncInputStream source)
Uploads the contents of the given
AsyncInputStream to a GridFS bucket. |
org.reactivestreams.Publisher<org.bson.types.ObjectId> |
uploadFromStream(String filename,
AsyncInputStream source,
com.mongodb.client.gridfs.model.GridFSUploadOptions options)
Uploads the contents of the given
AsyncInputStream to a GridFS bucket. |
GridFSBucket |
withChunkSizeBytes(int chunkSizeBytes)
Create a new GridFSBucket instance with a new chunk size in bytes.
|
GridFSBucket |
withReadConcern(com.mongodb.ReadConcern readConcern)
Create a new MongoDatabase instance with a different read concern.
|
GridFSBucket |
withReadPreference(com.mongodb.ReadPreference readPreference)
Create a new GridFSBucket instance with a different read preference.
|
GridFSBucket |
withWriteConcern(com.mongodb.WriteConcern writeConcern)
Create a new GridFSBucket instance with a different write concern.
|
String getBucketName()
int getChunkSizeBytes()
com.mongodb.WriteConcern getWriteConcern()
WriteConcern
com.mongodb.ReadPreference getReadPreference()
ReadPreference
com.mongodb.ReadConcern getReadConcern()
ReadConcern
GridFSBucket withChunkSizeBytes(int chunkSizeBytes)
chunkSizeBytes
- the new chunk size in bytes.GridFSBucket withReadPreference(com.mongodb.ReadPreference readPreference)
readPreference
- the new ReadPreference
for the databaseGridFSBucket withWriteConcern(com.mongodb.WriteConcern writeConcern)
writeConcern
- the new WriteConcern
for the databaseGridFSBucket withReadConcern(com.mongodb.ReadConcern readConcern)
readConcern
- the new ReadConcern
for the databaseGridFSUploadStream openUploadStream(String filename)
As the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection document is created in the files collection.
filename
- the filename for the streamGridFSUploadStream openUploadStream(String filename, com.mongodb.client.gridfs.model.GridFSUploadOptions options)
As the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection document is created in the files collection.
filename
- the filename for the streamoptions
- the GridFSUploadOptionsGridFSUploadStream openUploadStream(org.bson.BsonValue id, String filename)
As the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection document is created in the files collection.
id
- the custom id value of the filefilename
- the filename for the streamGridFSUploadStream openUploadStream(org.bson.BsonValue id, String filename, com.mongodb.client.gridfs.model.GridFSUploadOptions options)
As the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection document is created in the files collection.
id
- the custom id value of the filefilename
- the filename for the streamoptions
- the GridFSUploadOptionsorg.reactivestreams.Publisher<org.bson.types.ObjectId> uploadFromStream(String filename, AsyncInputStream source)
AsyncInputStream
to a GridFS bucket.
Reads the contents of the user file from the source
and uploads it as chunks in the chunks collection. After all the
chunks have been uploaded, it creates a files collection document for filename
in the files collection.
filename
- the filename for the streamsource
- the Stream providing the file dataorg.reactivestreams.Publisher<org.bson.types.ObjectId> uploadFromStream(String filename, AsyncInputStream source, com.mongodb.client.gridfs.model.GridFSUploadOptions options)
AsyncInputStream
to a GridFS bucket.
Reads the contents of the user file from the source
and uploads it as chunks in the chunks collection. After all the
chunks have been uploaded, it creates a files collection document for filename
in the files collection.
filename
- the filename for the streamsource
- the Stream providing the file dataoptions
- the GridFSUploadOptionsorg.reactivestreams.Publisher<Success> uploadFromStream(org.bson.BsonValue id, String filename, AsyncInputStream source)
AsyncInputStream
to a GridFS bucket.
Reads the contents of the user file from the source
and uploads it as chunks in the chunks collection. After all the
chunks have been uploaded, it creates a files collection document for filename
in the files collection.
id
- the custom id value of the filefilename
- the filename for the streamsource
- the Stream providing the file dataorg.reactivestreams.Publisher<Success> uploadFromStream(org.bson.BsonValue id, String filename, AsyncInputStream source, com.mongodb.client.gridfs.model.GridFSUploadOptions options)
AsyncInputStream
to a GridFS bucket.
Reads the contents of the user file from the source
and uploads it as chunks in the chunks collection. After all the
chunks have been uploaded, it creates a files collection document for filename
in the files collection.
id
- the custom id value of the filefilename
- the filename for the streamsource
- the Stream providing the file dataoptions
- the GridFSUploadOptionsGridFSDownloadStream openDownloadStream(org.bson.types.ObjectId id)
id
.id
- the ObjectId of the file to be put into a stream.org.reactivestreams.Publisher<Long> downloadToStream(org.bson.types.ObjectId id, AsyncOutputStream destination)
id
and writes the contents to the destination
AsyncOutputStream.id
- the ObjectId of the file to be written to the destination streamdestination
- the destination streamGridFSDownloadStream openDownloadStream(org.bson.BsonValue id)
id
.id
- the custom id value of the file, to be put into a stream.org.reactivestreams.Publisher<Long> downloadToStream(org.bson.BsonValue id, AsyncOutputStream destination)
id
and writes the contents to the destination
AsyncOutputStream.id
- the custom id of the file, to be written to the destination streamdestination
- the destination streamGridFSDownloadStream openDownloadStream(String filename)
filename
.filename
- the name of the file to be downloadedGridFSDownloadStream openDownloadStream(String filename, com.mongodb.client.gridfs.model.GridFSDownloadOptions options)
filename
and the revision
in options
.filename
- the name of the file to be downloadedoptions
- the download optionsorg.reactivestreams.Publisher<Long> downloadToStream(String filename, AsyncOutputStream destination)
filename
and writes the contents to
the destination
Stream.filename
- the name of the file to be downloadeddestination
- the destination streamorg.reactivestreams.Publisher<Long> downloadToStream(String filename, AsyncOutputStream destination, com.mongodb.client.gridfs.model.GridFSDownloadOptions options)
filename
and by the revision in options
and writes the
contents to the destination
Stream.filename
- the name of the file to be downloadeddestination
- the destination streamoptions
- the download optionsGridFSFindPublisher find()
GridFSFindPublisher find(org.bson.conversions.Bson filter)
Below is an example of filtering against the filename and some nested metadata that can also be stored along with the file data:
Filters.and(Filters.eq("filename", "mongodb.png"), Filters.eq("metadata.contentType", "image/png"));
filter
- the query filterFilters
org.reactivestreams.Publisher<Success> delete(org.bson.types.ObjectId id)
id
, delete this stored file's files collection document and associated chunks from a GridFS bucket.id
- the ObjectId of the file to be deletedorg.reactivestreams.Publisher<Success> delete(org.bson.BsonValue id)
id
, delete this stored file's files collection document and associated chunks from a GridFS bucket.id
- the ObjectId of the file to be deletedorg.reactivestreams.Publisher<Success> rename(org.bson.types.ObjectId id, String newFilename)
id
.id
- the id of the file in the files collection to renamenewFilename
- the new filename for the fileorg.reactivestreams.Publisher<Success> rename(org.bson.BsonValue id, String newFilename)
id
.id
- the id of the file in the files collection to renamenewFilename
- the new filename for the fileorg.reactivestreams.Publisher<Success> drop()