@ThreadSafe public interface GridFSBucket
Modifier and Type | Method and Description |
---|---|
void |
delete(ObjectId id)
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
void |
downloadToStream(BsonValue id,
OutputStream destination)
Deprecated.
using custom id values for with GridFS is no longer supported
|
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)
Downloads the contents of the latest version of the stored file specified by
filename and writes the contents to
the destination Stream. |
void |
downloadToStreamByName(String filename,
OutputStream destination,
GridFSDownloadByNameOptions 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 |
drop()
Drops the data associated with this bucket from the database.
|
GridFSFindIterable |
find()
Finds all documents in the files collection.
|
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.
|
ReadPreference |
getReadPreference()
Get the read preference for the GridFSBucket.
|
WriteConcern |
getWriteConcern()
Get the write concern for the GridFSBucket.
|
GridFSDownloadStream |
openDownloadStream(BsonValue id)
Deprecated.
using custom id values for with GridFS is no longer supported
|
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)
Opens a Stream from which the application can read the contents of the latest version of the stored file specified by the
filename . |
GridFSDownloadStream |
openDownloadStreamByName(String filename,
GridFSDownloadByNameOptions 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(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.
|
void |
rename(ObjectId id,
String newFilename)
Renames the stored file with the specified
id . |
ObjectId |
uploadFromStream(String filename,
InputStream source)
Uploads a user file to a GridFS bucket.
|
ObjectId |
uploadFromStream(String filename,
InputStream source,
GridFSUploadOptions options)
Uploads a user file to a GridFS bucket.
|
GridFSBucket |
withChunkSizeBytes(int chunkSizeBytes)
Create a new GridFSBucket instance with a new chunk size in bytes.
|
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
GridFSBucket withChunkSizeBytes(int chunkSizeBytes)
chunkSizeBytes
- the new chunk size in bytes.GridFSBucket withReadPreference(ReadPreference readPreference)
readPreference
- the new ReadPreference
for the databaseGridFSBucket withWriteConcern(WriteConcern writeConcern)
writeConcern
- the new WriteConcern
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, 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 GridFSUploadOptionsObjectId uploadFromStream(String filename, InputStream source)
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)
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 GridFSUploadOptionsGridFSDownloadStream openDownloadStream(ObjectId id)
id
.id
- the ObjectId of the file to be put into a stream.void 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 stream@Deprecated GridFSDownloadStream openDownloadStream(BsonValue id)
id
.id
- the custom id value of the file, to be put into a stream.@Deprecated void 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 streamGridFSDownloadStream openDownloadStreamByName(String filename)
filename
.filename
- the name of the file to be downloadedGridFSDownloadStream openDownloadStreamByName(String filename, GridFSDownloadByNameOptions options)
filename
and the revision
in options
.filename
- the name of the file to be downloadedoptions
- the download optionsvoid downloadToStreamByName(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 downloadToStreamByName(String filename, OutputStream destination, GridFSDownloadByNameOptions 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 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
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 rename(ObjectId id, String newFilename)
id
.id
- the id of the file in the files collection to renamenewFilename
- the new filename for the filevoid drop()