@ThreadSafe public interface GridFSBucket
Modifier and Type | Method | Description |
---|---|---|
void |
deleteâ(ClientSession clientSession,
BsonValue id) |
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
void |
deleteâ(ClientSession clientSession,
ObjectId id) |
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
void |
deleteâ(BsonValue id) |
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
void |
deleteâ(ObjectId id) |
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
void |
downloadToStreamâ(ClientSession clientSession,
String filename,
OutputStream destination) |
Downloads the contents of the latest version of the stored file specified by
filename and writes the contents to
the destination Stream. |
void |
downloadToStreamâ(ClientSession clientSession,
String filename,
OutputStream destination,
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. |
void |
downloadToStreamâ(ClientSession clientSession,
BsonValue id,
OutputStream destination) |
Downloads the contents of the stored file specified by
id and writes the contents to the destination Stream. |
void |
downloadToStreamâ(ClientSession clientSession,
ObjectId id,
OutputStream destination) |
Downloads the contents of the stored file specified by
id and writes the contents to the destination Stream. |
void |
downloadToStreamâ(String filename,
OutputStream destination) |
Downloads the contents of the latest version of the stored file specified by
filename and writes the contents to
the destination Stream. |
void |
downloadToStreamâ(String filename,
OutputStream destination,
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. |
void |
downloadToStreamâ(BsonValue id,
OutputStream destination) |
Downloads the contents of the stored file specified by
id and writes the contents to the destination Stream. |
void |
downloadToStreamâ(ObjectId id,
OutputStream destination) |
Downloads the contents of the stored file specified by
id and writes the contents to the destination Stream. |
void |
downloadToStreamByNameâ(String filename,
OutputStream destination) |
Deprecated.
use
downloadToStream(String, OutputStream) instead. |
void |
downloadToStreamByNameâ(String filename,
OutputStream destination,
GridFSDownloadByNameOptions options) |
Deprecated.
|
void |
dropâ() |
Drops the data associated with this bucket from the database.
|
void |
dropâ(ClientSession clientSession) |
Drops the data associated with this bucket from the database.
|
GridFSFindIterable |
findâ() |
Finds all documents in the files collection.
|
GridFSFindIterable |
findâ(ClientSession clientSession) |
Finds all documents in the files collection.
|
GridFSFindIterable |
findâ(ClientSession clientSession,
Bson filter) |
Finds all documents in the collection that match the filter.
|
GridFSFindIterable |
findâ(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.
|
ReadConcern |
getReadConcernâ() |
Get the read concern for the GridFSBucket.
|
ReadPreference |
getReadPreferenceâ() |
Get the read preference for the GridFSBucket.
|
WriteConcern |
getWriteConcernâ() |
Get the write concern for the GridFSBucket.
|
GridFSDownloadStream |
openDownloadStreamâ(ClientSession clientSession,
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â(ClientSession clientSession,
String filename,
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 . |
GridFSDownloadStream |
openDownloadStreamâ(ClientSession clientSession,
BsonValue id) |
Opens a Stream from which the application can read the contents of the stored file specified by
id . |
GridFSDownloadStream |
openDownloadStreamâ(ClientSession clientSession,
ObjectId id) |
Opens a Stream 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,
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 . |
GridFSDownloadStream |
openDownloadStreamâ(BsonValue id) |
Opens a Stream from which the application can read the contents of the stored file specified by
id . |
GridFSDownloadStream |
openDownloadStreamâ(ObjectId id) |
Opens a Stream from which the application can read the contents of the stored file specified by
id . |
GridFSDownloadStream |
openDownloadStreamByNameâ(String filename) |
Deprecated.
use
openDownloadStream(String) instead. |
GridFSDownloadStream |
openDownloadStreamByNameâ(String filename,
GridFSDownloadByNameOptions options) |
Deprecated.
use
openDownloadStream(String, GridFSDownloadOptions) instead. |
GridFSUploadStream |
openUploadStreamâ(ClientSession clientSession,
String filename) |
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStreamâ(ClientSession clientSession,
String filename,
GridFSUploadOptions options) |
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStreamâ(ClientSession clientSession,
BsonValue id,
String filename) |
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStreamâ(ClientSession clientSession,
BsonValue id,
String filename,
GridFSUploadOptions options) |
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStreamâ(ClientSession clientSession,
ObjectId id,
String filename) |
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStreamâ(String filename) |
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStreamâ(String filename,
GridFSUploadOptions options) |
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStreamâ(BsonValue id,
String filename) |
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStreamâ(BsonValue id,
String filename,
GridFSUploadOptions options) |
Opens a Stream that the application can write the contents of the file to.
|
void |
renameâ(ClientSession clientSession,
BsonValue id,
String newFilename) |
Renames the stored file with the specified
id . |
void |
renameâ(ClientSession clientSession,
ObjectId id,
String newFilename) |
Renames the stored file with the specified
id . |
void |
renameâ(BsonValue id,
String newFilename) |
Renames the stored file with the specified
id . |
void |
renameâ(ObjectId id,
String newFilename) |
Renames the stored file with the specified
id . |
ObjectId |
uploadFromStreamâ(ClientSession clientSession,
String filename,
InputStream source) |
Uploads the contents of the given
InputStream to a GridFS bucket. |
ObjectId |
uploadFromStreamâ(ClientSession clientSession,
String filename,
InputStream source,
GridFSUploadOptions options) |
Uploads the contents of the given
InputStream to a GridFS bucket. |
void |
uploadFromStreamâ(ClientSession clientSession,
BsonValue id,
String filename,
InputStream source) |
Uploads the contents of the given
InputStream to a GridFS bucket. |
void |
uploadFromStreamâ(ClientSession clientSession,
BsonValue id,
String filename,
InputStream source,
GridFSUploadOptions options) |
Uploads the contents of the given
InputStream to a GridFS bucket. |
ObjectId |
uploadFromStreamâ(String filename,
InputStream source) |
Uploads the contents of the given
InputStream to a GridFS bucket. |
ObjectId |
uploadFromStreamâ(String filename,
InputStream source,
GridFSUploadOptions options) |
Uploads the contents of the given
InputStream to a GridFS bucket. |
void |
uploadFromStreamâ(BsonValue id,
String filename,
InputStream source) |
Uploads the contents of the given
InputStream to a GridFS bucket. |
void |
uploadFromStreamâ(BsonValue id,
String filename,
InputStream source,
GridFSUploadOptions options) |
Uploads the contents of the given
InputStream to a GridFS bucket. |
GridFSBucket |
withChunkSizeBytesâ(int chunkSizeBytes) |
Create a new GridFSBucket instance with a new chunk size in bytes.
|
GridFSBucket |
withReadConcernâ(ReadConcern readConcern) |
Create a new GridFSBucket instance with a different read concern.
|
GridFSBucket |
withReadPreferenceâ(ReadPreference readPreference) |
Create a new GridFSBucket instance with a different read preference.
|
GridFSBucket |
withWriteConcernâ(WriteConcern writeConcern) |
Create a new GridFSBucket instance with a different write concern.
|
String getBucketNameâ()
int getChunkSizeBytesâ()
WriteConcern getWriteConcernâ()
WriteConcern
ReadPreference getReadPreferenceâ()
ReadPreference
ReadConcern getReadConcernâ()
ReadConcern
GridFSBucket withChunkSizeBytesâ(int chunkSizeBytes)
chunkSizeBytes
- the new chunk size in bytes.GridFSBucket withReadPreferenceâ(ReadPreference readPreference)
readPreference
- the new ReadPreference
for the GridFSBucketGridFSBucket withWriteConcernâ(WriteConcern writeConcern)
writeConcern
- the new WriteConcern
for the GridFSBucketGridFSBucket withReadConcernâ(ReadConcern readConcern)
readConcern
- the new ReadConcern
for the GridFSBucketGridFSUploadStream 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, 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â(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â(BsonValue id, String filename, 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 GridFSUploadOptionsGridFSUploadStream openUploadStreamâ(ClientSession clientSession, 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.
clientSession
- the client session with which to associate this operationfilename
- the filename for the streamGridFSUploadStream openUploadStreamâ(ClientSession clientSession, String filename, 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.
clientSession
- the client session with which to associate this operationfilename
- the filename for the streamoptions
- the GridFSUploadOptionsGridFSUploadStream openUploadStreamâ(ClientSession clientSession, 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.
clientSession
- the client session with which to associate this operationid
- the custom id value of the filefilename
- the filename for the streamGridFSUploadStream openUploadStreamâ(ClientSession clientSession, ObjectId 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.
clientSession
- the client session with which to associate this operationid
- the custom id value of the filefilename
- the filename for the streamGridFSUploadStream openUploadStreamâ(ClientSession clientSession, BsonValue id, String filename, 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.
clientSession
- the client session with which to associate this operationid
- the custom id value of the filefilename
- the filename for the streamoptions
- the GridFSUploadOptionsObjectId uploadFromStreamâ(String filename, InputStream source)
InputStream
to a GridFS bucket.
Reads the contents of the user file from the Stream
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 dataObjectId uploadFromStreamâ(String filename, InputStream source, GridFSUploadOptions options)
InputStream
to a GridFS bucket.
Reads the contents of the user file from the Stream
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 GridFSUploadOptionsvoid uploadFromStreamâ(BsonValue id, String filename, InputStream source)
InputStream
to a GridFS bucket.
Reads the contents of the user file from the Stream
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 datavoid uploadFromStreamâ(BsonValue id, String filename, InputStream source, GridFSUploadOptions options)
InputStream
to a GridFS bucket.
Reads the contents of the user file from the Stream
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 GridFSUploadOptionsObjectId uploadFromStreamâ(ClientSession clientSession, String filename, InputStream source)
InputStream
to a GridFS bucket.
Reads the contents of the user file from the Stream
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.
clientSession
- the client session with which to associate this operationfilename
- the filename for the streamsource
- the Stream providing the file dataObjectId uploadFromStreamâ(ClientSession clientSession, String filename, InputStream source, GridFSUploadOptions options)
InputStream
to a GridFS bucket.
Reads the contents of the user file from the Stream
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.
clientSession
- the client session with which to associate this operationfilename
- the filename for the streamsource
- the Stream providing the file dataoptions
- the GridFSUploadOptionsvoid uploadFromStreamâ(ClientSession clientSession, BsonValue id, String filename, InputStream source)
InputStream
to a GridFS bucket.
Reads the contents of the user file from the Stream
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.
clientSession
- the client session with which to associate this operationid
- the custom id value of the filefilename
- the filename for the streamsource
- the Stream providing the file datavoid uploadFromStreamâ(ClientSession clientSession, BsonValue id, String filename, InputStream source, GridFSUploadOptions options)
InputStream
to a GridFS bucket.
Reads the contents of the user file from the Stream
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.
clientSession
- the client session with which to associate this operationid
- the custom id value of the filefilename
- the filename for the streamsource
- the Stream providing the file dataoptions
- the GridFSUploadOptionsGridFSDownloadStream openDownloadStreamâ(ObjectId id)
id
.id
- the ObjectId of the file to be put into a stream.GridFSDownloadStream openDownloadStreamâ(BsonValue id)
id
.id
- the custom id value of the file, to be put into a stream.GridFSDownloadStream openDownloadStreamâ(String filename)
filename
.filename
- the name of the file to be downloadedGridFSDownloadStream openDownloadStreamâ(String filename, GridFSDownloadOptions options)
filename
and the revision
in options
.filename
- the name of the file to be downloadedoptions
- the download optionsGridFSDownloadStream openDownloadStreamâ(ClientSession clientSession, ObjectId id)
id
.clientSession
- the client session with which to associate this operationid
- the ObjectId of the file to be put into a stream.GridFSDownloadStream openDownloadStreamâ(ClientSession clientSession, BsonValue id)
id
.clientSession
- the client session with which to associate this operationid
- the custom id value of the file, to be put into a stream.GridFSDownloadStream openDownloadStreamâ(ClientSession clientSession, String filename)
filename
.clientSession
- the client session with which to associate this operationfilename
- the name of the file to be downloadedGridFSDownloadStream openDownloadStreamâ(ClientSession clientSession, String filename, GridFSDownloadOptions options)
filename
and the revision
in options
.clientSession
- the client session with which to associate this operationfilename
- the name of the file to be downloadedoptions
- the download optionsvoid downloadToStreamâ(ObjectId id, OutputStream destination)
id
and writes the contents to the destination
Stream.id
- the ObjectId of the file to be written to the destination streamdestination
- the destination streamvoid downloadToStreamâ(BsonValue id, OutputStream destination)
id
and writes the contents to the destination
Stream.id
- the custom id of the file, to be written to the destination streamdestination
- the destination streamvoid downloadToStreamâ(String filename, OutputStream destination)
filename
and writes the contents to
the destination
Stream.filename
- the name of the file to be downloadeddestination
- the destination streamvoid downloadToStreamâ(String filename, OutputStream destination, 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 optionsvoid downloadToStreamâ(ClientSession clientSession, ObjectId id, OutputStream destination)
id
and writes the contents to the destination
Stream.clientSession
- the client session with which to associate this operationid
- the ObjectId of the file to be written to the destination streamdestination
- the destination streamvoid downloadToStreamâ(ClientSession clientSession, BsonValue id, OutputStream destination)
id
and writes the contents to the destination
Stream.clientSession
- the client session with which to associate this operationid
- the custom id of the file, to be written to the destination streamdestination
- the destination streamvoid downloadToStreamâ(ClientSession clientSession, String filename, OutputStream destination)
filename
and writes the contents to
the destination
Stream.clientSession
- the client session with which to associate this operationfilename
- the name of the file to be downloadeddestination
- the destination streamvoid downloadToStreamâ(ClientSession clientSession, String filename, OutputStream destination, GridFSDownloadOptions options)
filename
and by the revision in options
and writes the
contents to the destination
Stream.clientSession
- the client session with which to associate this operationfilename
- the name of the file to be downloadeddestination
- the destination streamoptions
- the download optionsGridFSFindIterable findâ()
GridFSFindIterable findâ(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
GridFSFindIterable findâ(ClientSession clientSession)
GridFSFindIterable findâ(ClientSession clientSession, 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"));
void deleteâ(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 deletedvoid deleteâ(BsonValue id)
id
, delete this stored file's files collection document and associated chunks from a GridFS bucket.id
- the id of the file to be deletedvoid deleteâ(ClientSession clientSession, ObjectId id)
id
, delete this stored file's files collection document and associated chunks from a GridFS bucket.clientSession
- the client session with which to associate this operationid
- the ObjectId of the file to be deletedvoid deleteâ(ClientSession clientSession, BsonValue id)
id
, delete this stored file's files collection document and associated chunks from a GridFS bucket.clientSession
- the client session with which to associate this operationid
- the id of the file to be deletedvoid renameâ(ObjectId id, String newFilename)
id
.id
- the id of the file in the files collection to renamenewFilename
- the new filename for the filevoid renameâ(BsonValue id, String newFilename)
id
.id
- the id of the file in the files collection to renamenewFilename
- the new filename for the filevoid renameâ(ClientSession clientSession, ObjectId id, String newFilename)
id
.clientSession
- the client session with which to associate this operationid
- the id of the file in the files collection to renamenewFilename
- the new filename for the filevoid renameâ(ClientSession clientSession, BsonValue id, String newFilename)
id
.clientSession
- the client session with which to associate this operationid
- the id of the file in the files collection to renamenewFilename
- the new filename for the filevoid dropâ()
void dropâ(ClientSession clientSession)
clientSession
- the client session with which to associate this operation@Deprecated GridFSDownloadStream openDownloadStreamByNameâ(String filename)
openDownloadStream(String)
instead.filename
.filename
- the name of the file to be downloaded@Deprecated GridFSDownloadStream openDownloadStreamByNameâ(String filename, GridFSDownloadByNameOptions options)
openDownloadStream(String, GridFSDownloadOptions)
instead.filename
and the revision
in options
.filename
- the name of the file to be downloadedoptions
- the download options@Deprecated void downloadToStreamByNameâ(String filename, OutputStream destination)
downloadToStream(String, OutputStream)
instead.filename
and writes the contents to
the destination
Stream.filename
- the name of the file to be downloadeddestination
- the destination stream@Deprecated void downloadToStreamByNameâ(String filename, OutputStream destination, GridFSDownloadByNameOptions options)
downloadToStream(String, OutputStream, GridFSDownloadOptions)
instead.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 options