Mongo.FileStorage
8.1.2
See the version list below for details.
dotnet add package Mongo.FileStorage --version 8.1.2
NuGet\Install-Package Mongo.FileStorage -Version 8.1.2
<PackageReference Include="Mongo.FileStorage" Version="8.1.2" />
<PackageVersion Include="Mongo.FileStorage" Version="8.1.2" />
<PackageReference Include="Mongo.FileStorage" />
paket add Mongo.FileStorage --version 8.1.2
#r "nuget: Mongo.FileStorage, 8.1.2"
#:package Mongo.FileStorage@8.1.2
#addin nuget:?package=Mongo.FileStorage&version=8.1.2
#tool nuget:?package=Mongo.FileStorage&version=8.1.2
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
{
Task<ObjectId> UploadAsync(FileStream fileStream);
Task<MemoryStream> DownloadAsync(string idOrName);
Task<GridFSFileInfo<ObjectId>> GetAsync(string idOrName);
Task DeleteAsync(ObjectId fileId);
}
}
Usage
To upload a file
Example:
var fs = File.OpenRead(filePath);
var fileId = await this.fileStorageRepository.UploadAsync(fs);
To download a file
Example:
MemoryStream file = await this.fileStorageRepository.DownloadAsync(idOrName);
To get a file
Example:
GridFSFileInfo<ObjectId> file = await this.fileStorageRepository.GetAsync(idOrName);
To delete a file
Example:
await this.fileStorageRepository.DeleteAsync(fileId);
Namespace Mongo.FileStorage.DependencyInjection
An extension method has been added to facilitate the registration of the IFileStorage repository.
Example:
services.ResisterFileStorageRepository(RegisterMode.Transient);
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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- 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 |