Class GridFSBucket
Represents a GridFS bucket.
public class GridFSBucket : GridFSBucket<ObjectId>, IGridFSBucket, IGridFSBucket<ObjectId>
- Inheritance
-
GridFSBucket
- Implements
- Inherited Members
Constructors
GridFSBucket(IMongoDatabase, GridFSBucketOptions)
Initializes a new instance of the GridFSBucket class.
public GridFSBucket(IMongoDatabase database, GridFSBucketOptions options = null)
Parameters
database
IMongoDatabaseThe database.
options
GridFSBucketOptionsThe options.
Methods
Delete(BsonValue, CancellationToken)
Deletes a file from GridFS.
public void Delete(BsonValue id, CancellationToken cancellationToken = default)
Parameters
id
BsonValueThe file id.
cancellationToken
CancellationTokenThe cancellation token.
DeleteAsync(BsonValue, CancellationToken)
Deletes a file from GridFS.
public Task DeleteAsync(BsonValue id, CancellationToken cancellationToken = default)
Parameters
id
BsonValueThe file id.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A Task.
DownloadAsBytes(BsonValue, GridFSDownloadOptions, CancellationToken)
Downloads a file stored in GridFS and returns it as a byte array.
public byte[] DownloadAsBytes(BsonValue id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)
Parameters
id
BsonValueThe file id.
options
GridFSDownloadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- byte[]
A byte array containing the contents of the file stored in GridFS.
DownloadAsBytesAsync(BsonValue, GridFSDownloadOptions, CancellationToken)
Downloads a file stored in GridFS and returns it as a byte array.
public Task<byte[]> DownloadAsBytesAsync(BsonValue id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)
Parameters
id
BsonValueThe file id.
options
GridFSDownloadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<byte[]>
A Task whose result is a byte array containing the contents of the file stored in GridFS.
DownloadToStream(BsonValue, Stream, GridFSDownloadOptions, CancellationToken)
Downloads a file stored in GridFS and writes the contents to a stream.
public void DownloadToStream(BsonValue id, Stream destination, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)
Parameters
id
BsonValueThe file id.
destination
StreamThe destination.
options
GridFSDownloadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
DownloadToStreamAsync(BsonValue, Stream, GridFSDownloadOptions, CancellationToken)
Downloads a file stored in GridFS and writes the contents to a stream.
public Task DownloadToStreamAsync(BsonValue id, Stream destination, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)
Parameters
id
BsonValueThe file id.
destination
StreamThe destination.
options
GridFSDownloadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A Task.
Find(FilterDefinition<GridFSFileInfo>, GridFSFindOptions, CancellationToken)
Finds matching entries from the files collection.
public IAsyncCursor<GridFSFileInfo> Find(FilterDefinition<GridFSFileInfo> filter, GridFSFindOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<GridFSFileInfo>The filter.
options
GridFSFindOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- IAsyncCursor<GridFSFileInfo>
A cursor of files collection documents.
FindAsync(FilterDefinition<GridFSFileInfo>, GridFSFindOptions, CancellationToken)
Finds matching entries from the files collection.
public Task<IAsyncCursor<GridFSFileInfo>> FindAsync(FilterDefinition<GridFSFileInfo> filter, GridFSFindOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<GridFSFileInfo>The filter.
options
GridFSFindOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IAsyncCursor<GridFSFileInfo>>
A Task whose result is a cursor of files collection documents.
OpenDownloadStream(BsonValue, GridFSDownloadOptions, CancellationToken)
Opens a Stream that can be used by the application to read data from a GridFS file.
public GridFSDownloadStream OpenDownloadStream(BsonValue id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)
Parameters
id
BsonValueThe file id.
options
GridFSDownloadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- GridFSDownloadStream
A Stream.
OpenDownloadStreamAsync(BsonValue, GridFSDownloadOptions, CancellationToken)
Opens a Stream that can be used by the application to read data from a GridFS file.
public Task<GridFSDownloadStream> OpenDownloadStreamAsync(BsonValue id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)
Parameters
id
BsonValueThe file id.
options
GridFSDownloadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<GridFSDownloadStream>
A Task whose result is a Stream.
OpenUploadStream(string, GridFSUploadOptions, CancellationToken)
Opens a Stream that can be used by the application to write data to a GridFS file.
public GridFSUploadStream OpenUploadStream(string filename, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)
Parameters
filename
stringThe filename.
options
GridFSUploadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- GridFSUploadStream
A Stream.
OpenUploadStreamAsync(string, GridFSUploadOptions, CancellationToken)
Opens a Stream that can be used by the application to write data to a GridFS file.
public Task<GridFSUploadStream> OpenUploadStreamAsync(string filename, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)
Parameters
filename
stringThe filename.
options
GridFSUploadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<GridFSUploadStream>
A Task whose result is a Stream.
Rename(BsonValue, string, CancellationToken)
Renames a GridFS file.
public void Rename(BsonValue id, string newFilename, CancellationToken cancellationToken = default)
Parameters
id
BsonValueThe file id.
newFilename
stringThe new filename.
cancellationToken
CancellationTokenThe cancellation token.
RenameAsync(BsonValue, string, CancellationToken)
Renames a GridFS file.
public Task RenameAsync(BsonValue id, string newFilename, CancellationToken cancellationToken = default)
Parameters
id
BsonValueThe file id.
newFilename
stringThe new filename.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A Task.
UploadFromBytes(string, byte[], GridFSUploadOptions, CancellationToken)
Uploads a file (or a new revision of a file) to GridFS.
public ObjectId UploadFromBytes(string filename, byte[] source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)
Parameters
filename
stringThe filename.
source
byte[]The source.
options
GridFSUploadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ObjectId
The id of the new file.
UploadFromBytesAsync(string, byte[], GridFSUploadOptions, CancellationToken)
Uploads a file (or a new revision of a file) to GridFS.
public Task<ObjectId> UploadFromBytesAsync(string filename, byte[] source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)
Parameters
filename
stringThe filename.
source
byte[]The source.
options
GridFSUploadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
UploadFromStream(string, Stream, GridFSUploadOptions, CancellationToken)
Uploads a file (or a new revision of a file) to GridFS.
public ObjectId UploadFromStream(string filename, Stream source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)
Parameters
filename
stringThe filename.
source
StreamThe source.
options
GridFSUploadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ObjectId
The id of the new file.
UploadFromStreamAsync(string, Stream, GridFSUploadOptions, CancellationToken)
Uploads a file (or a new revision of a file) to GridFS.
public Task<ObjectId> UploadFromStreamAsync(string filename, Stream source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)
Parameters
filename
stringThe filename.
source
StreamThe source.
options
GridFSUploadOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.