Mongo.FileStorage
8.1.7
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Mongo.FileStorage --version 8.1.7
NuGet\Install-Package Mongo.FileStorage -Version 8.1.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mongo.FileStorage" Version="8.1.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mongo.FileStorage" Version="8.1.7" />
<PackageReference Include="Mongo.FileStorage" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mongo.FileStorage --version 8.1.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Mongo.FileStorage, 8.1.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mongo.FileStorage@8.1.7
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mongo.FileStorage&version=8.1.7
#tool nuget:?package=Mongo.FileStorage&version=8.1.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Mongo.FileStorage
Library to store files using MongoDB
Required environment variables
"MONGODB_CONNECTION_STRING"(e.g., "mongodb://root:root@localhost:27017")"MONGODB_DATABASE_NAME"(default: "files_db")"BUCKET_NAME"(default: "files_bucket")"CHUNK_SIZE_BYTES"(default: 32768)
Interface
namespace Mongo.FileStorage.Repositories
{
using MongoDB.Bson;
using MongoDB.Driver.GridFS;
public interface IFileStorageRepository
{
GridFSBucket Bucket { get; }
Task<ObjectId> UploadAsync(FileStream fileStream);
Task<MemoryStream> DownloadAsStreamAsync(ObjectId fileId);
Task<MemoryStream> DownloadAsStreamAsync(string idOrName);
Task<byte[]> DownloadAsByteArrayAsync(ObjectId fileId);
Task<byte[]> DownloadAsByteArrayAsync(string idOrName);
Task<GridFSFileInfo<ObjectId>> GetFileInfoAsync(ObjectId fileId);
Task<GridFSFileInfo<ObjectId>> GetFileInfoAsync(string idOrName);
Task DeleteAsync(ObjectId fileId);
Task DeleteAsync(string fileId);
[Obsolete("Use DownloadAsStreamAsync instead as this method will be removed.")]
Task<MemoryStream> DownloadAsync(string idOrName);
[Obsolete("Use GetFileInfoAsync instead as this method will be removed")]
Task<GridFSFileInfo<ObjectId>> GetAsync(string idOrName);
}
}
Usage
First, register the
IFileStorageRepositoryin the services collection.
using Mongo.FileStorage.DependencyInjection;
...
services.RegisterFileStorageRepository(RegisterMode.Transient);
To upload a file
var fs = File.OpenRead(filePath);
var fileId = await this.fileStorageRepository.UploadAsync(fs);
To download a file
MemoryStream file = await this.fileStorageRepository.DownloadAsStreamAsync(idOrName);
To get details from a file
GridFSFileInfo<ObjectId> file = await this.fileStorageRepository.GetFileInfoAsync(idOrName);
To delete a file
await this.fileStorageRepository.DeleteAsync(fileId);
Note
- In order to run the tests, you must first run
docker compose up -d. - You can then manage the database at http://localhost:8081, with:
- User: user
- Password: pwd
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- MongoDB.Driver (>= 2.29.0)
- MongoDB.Driver.GridFS (>= 2.29.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.1.3 | 90 | 9/4/2026 |
| 10.1.2 | 109 | 7/31/2026 |
| 10.1.1 | 112 | 5/17/2026 |
| 10.1.0 | 110 | 4/6/2026 |
| 10.0.1 | 114 | 2/28/2026 |
| 10.0.0 | 143 | 12/6/2025 |
| 9.0.4 | 210 | 9/20/2025 |
| 9.0.3 | 134 | 5/10/2025 |
| 9.0.2 | 179 | 3/28/2025 |
| 9.0.1 | 169 | 2/23/2025 |
| 9.0.0 | 161 | 12/8/2024 |
| 8.2.1 | 145 | 11/22/2024 |
| 8.2.0 | 169 | 11/1/2024 |
| 8.1.7 | 162 | 10/12/2024 |
| 8.1.6 | 157 | 10/11/2024 |
| 8.1.5 | 170 | 10/4/2024 |
| 8.1.4 | 168 | 9/29/2024 |
| 8.1.3 | 176 | 9/29/2024 |
| 8.1.2 | 170 | 9/28/2024 |
| 8.1.1 | 175 | 9/27/2024 |