Blobject.AmazonS3
5.0.20
dotnet add package Blobject.AmazonS3 --version 5.0.20
NuGet\Install-Package Blobject.AmazonS3 -Version 5.0.20
<PackageReference Include="Blobject.AmazonS3" Version="5.0.20" />
<PackageVersion Include="Blobject.AmazonS3" Version="5.0.20" />
<PackageReference Include="Blobject.AmazonS3" />
paket add Blobject.AmazonS3 --version 5.0.20
#r "nuget: Blobject.AmazonS3, 5.0.20"
#:package Blobject.AmazonS3@5.0.20
#addin nuget:?package=Blobject.AmazonS3&version=5.0.20
#tool nuget:?package=Blobject.AmazonS3&version=5.0.20
Blobject
Blobject is a common, consistent storage interface for Microsoft Azure, Amazon S3, S3 compatible storage (i.e. Minio, Less3, View), CIFS (Windows file shares), NFS (Linux and UNIX file shares), Google Cloud Storage, and local filesystem written in C#.
| Library | Version | Downloads |
|---|---|---|
| Blobject.Core | ||
| Blobject.AmazonS3 | ||
| Blobject.AmazonS3Lite | ||
| Blobject.AzureBlob | ||
| Blobject.CIFS | ||
| Blobject.Disk | ||
| Blobject.GoogleCloud | ||
| Blobject.NFS |
Help, Feedback, Contribute
If you have any issues or feedback, please file an issue here in Github. We'd love to have you help by contributing code for new features, optimization to the existing codebase, ideas for future releases, or fixes!
Overview
This project was built to provide a simple interface over external storage to help support projects that need to work with potentially multiple storage providers. It is by no means a comprehensive interface, rather, it supports core methods for creation, retrieval, deletion, metadata, and enumeration.
Contributors
- @phpfui for adding the original code for BLOB copy functionality
- @Revazashvili for fixes related to byte array instantiation, Azure, and refactoring
- @courtzzz for keeping the region list updated
Dependencies
Though this library is MIT licensed, it is dependent upon other libraries, some of which carry a different license. Each of these libraries are included by reference, that is, none of their code has been modified.
| Package | URL | License |
|---|---|---|
| AWSSDK.S3 | https://github.com/aws/aws-sdk-net | Apache 2.0 |
| Azure.Storage.Blobs | https://github.com/Azure/azure-sdk-for-net | MIT |
| EzSmb | https://github.com/ume05rw/EzSmb | LGPL-3.0 |
| Google.Cloud.Storage.V1 | https://github.com/googleapis/google-cloud-dotnet | Apache 2.0 |
| SMBLibrary | https://github.com/TalAloni/SMBLibrary | LGPL-3.0 |
| NFS-Client | https://github.com/SonnyX/NFS-Client | Unknown, public |
| Nekodrive | https://github.com/nekoni/nekodrive | Unknown, public |
| S3Lite | https://github.com/jchristn/S3Lite | MIT |
New in v5.0.x
- Rename from
BlobHelpertoBlobject - Added support for CIFS, NFS, and Google Cloud Storage
- Remove use of continuation tokens for disk
- Add
S3Litevariant, not dependent on AWSSDK - Enumerate APIs now return an
IEnumerable<BlobMetadata>, no pagination required Blobject.AmazonS3andBlobject.AmazonS3Litev5.0.19 normalize AWS region aliases such asUSEast2to DNS-safe names such asus-east-2and default AWS S3 settings to HTTPSBlobject.Corev5.0.19 fixes streaming-first copy, bounded bulk operations, empty-write consistency, filter cloning, and case handling- Provider patch releases v5.0.19/v5.0.20 align stream APIs, empty writes, filter matching, and shared bulk behavior
- Provider packages now share common
WriteManyAsyncandEmptyAsyncbehavior with configurableMaxConcurrency - Refactor
Example Project
Refer to the Test project for exercising the library.
Automated Tests
The repository includes Touchstone-based automated contract tests. Test.Shared contains the runner-agnostic provider contract definitions. By default, the tests run against Blobject.Disk in a temporary directory and clean up after each case.
dotnet run --project src/Test.Automated/Test.Automated.csproj --framework net10.0
dotnet test src/Test.Xunit/Test.Xunit.csproj --framework net10.0
dotnet test src/Test.Nunit/Test.Nunit.csproj --framework net10.0
The default suite contains 80 contract cases. Add --include-stress true to Test.Automated to include large enumeration and large WriteManyAsync coverage.
dotnet run --project src/Test.Automated/Test.Automated.csproj --framework net10.0 -- --include-stress true
Test.Automated accepts provider-specific command-line overrides. Remote providers are isolated by a generated prefix and cleaned up by default.
dotnet run --project src/Test.Automated/Test.Automated.csproj --framework net10.0 -- \
--provider s3 \
--s3-access-key <access-key> \
--s3-secret-key <secret-key> \
--s3-region us-east-2 \
--s3-bucket <bucket> \
--prefix blobject-contract-tests
For S3-compatible storage, also supply --s3-endpoint, --s3-ssl, and --s3-base-url. Supported providers are disk, s3, s3lite, azure, gcp, cifs, and nfs; run Test.Automated --help for the full argument list. The xUnit and NUnit adapters use the same shared suite and can be configured with the equivalent BLOBJECT_TEST_* environment variables, such as BLOBJECT_TEST_PROVIDER, BLOBJECT_TEST_S3_BUCKET, and BLOBJECT_TEST_PREFIX.
dotnet test src/Test.Xunit/Test.Xunit.csproj --framework net10.0 \
-e BLOBJECT_TEST_PROVIDER=s3 \
-e BLOBJECT_TEST_S3_ACCESS_KEY=<access-key> \
-e BLOBJECT_TEST_S3_SECRET_KEY=<secret-key> \
-e BLOBJECT_TEST_S3_REGION=us-east-2 \
-e BLOBJECT_TEST_S3_BUCKET=<bucket>
The existing Test.* console applications remain available for interactive provider-specific testing.
Getting Started - AWS S3
using Blobject;
AwsSettings settings = new AwsSettings(
accessKey,
secretKey,
"us-west-1",
bucket);
BlobClient blobs = new BlobClient(settings);
AWS S3 region names are normalized against the current Amazon S3 regular endpoint region list. For example, USEast2, us_east_2, and us-east-2 are stored as us-east-2.
Getting Started - AWS S3 Compatible Storage (Minio, Less3, etc)
using Blobject.AmazonS3;
AwsSettings settings = new AwsSettings(
endpoint, // http://localhost:8000/
true, // enable or disable SSL
accessKey,
secretKey,
"us-west-1",
bucket,
baseUrl // i.e. http://localhost:8000/{bucket}/{key}
);
AmazonS3BlobClient blobs = new AmazonS3BlobClient(settings);
Getting Started - AWS S3 Lite (non-AWS library to reduce dependency drag)
using Blobject.AmazonS3Lite;
// Initialize settings as above
AmazonS3LiteBlobClient blobs = new AmazonS3LiteBlobClient(settings);
Getting Started - AWS S3 Anonymous Access
For accessing public buckets that don't require authentication, you can omit the access key and secret key:
using Blobject.AmazonS3Lite;
// Anonymous access to a public bucket
AwsSettings settings = new AwsSettings(
null, // accessKey - null for anonymous access
null, // secretKey - null for anonymous access
"us-west-1",
"public-bucket-name"
);
AmazonS3LiteBlobClient blobs = new AmazonS3LiteBlobClient(settings);
// Check if credentials are configured
Console.WriteLine("Has credentials: " + settings.HasCredentials); // False
// Read operations work on public buckets
byte[] data = await blobs.GetAsync("public-file.txt");
Note: Write and delete operations require authentication. Anonymous access is read-only.
Getting Started - Azure
using Blobject.AzureBlob;
AzureBlobSettings settings = new AzureBlobSettings(
accountName,
accessKey,
"https://[accountName].blob.core.windows.net/",
containerName);
AzureBlobClient blobs = new AzureBlobClient(settings);
Getting Started - Google Cloud
Important - you must have the JSON credentials for the service account, which includes the private key. Creation of these credentials requires the organization policy administrator role.
using Blobject.GoogleCloud;
GcpBlobSettings settings = new GcpBlobSettings(
projectId,
bucket,
"... JSON credentials for service account ..."
GcpBlobClient blobs = new GcpBlobClient(settings);
Getting Started - CIFS
using Blobject.CIFS;
CifsSettings settings = new CifsSettings(
"localhost",
username,
password,
sharename);
CifsBlobClient blobs = new CifsBlobClient(settings);
Getting Started - Disk
using Blobject.Disk;
DiskSettings settings = new DiskSettings("blobs");
DiskBlobClient blobs = new DiskBlobClient(settings);
Getting Started - NFS
using Blobject.NFS;
NfsSettings settings = new NfsSettings(
"localhost",
0, // user ID
0, // group ID,
sharename,
NfsVersionEnum.V3 // V2, V3, or V4
);
NfsBlobClient = new NfsBlobClient(settings);
Getting Started (Byte Arrays for Smaller Objects)
await blobs.WriteAsync("test", "text/plain", "This is some data"); // throws IOException
await blobs.WriteAsync("empty", "application/octet-stream", Array.Empty<byte>());
byte[] data = await blobs.GetAsync("test"); // throws IOException
bool exists = await blobs.ExistsAsync("test");
await blobs.DeleteAsync("test");
Getting Started (Streams for Larger Objects)
// Writing a file using a stream
FileInfo fi = new FileInfo(inputFile);
long contentLength = fi.Length;
using (FileStream fs = new FileStream(inputFile, FileMode.Open))
{
await _Blobs.WriteAsync("key", "content-type", contentLength, fs); // throws IOException
}
// Downloading to a stream
BlobData blob = await _Blobs.GetStreamAsync(key);
// read blob.ContentLength bytes from blob.Data
Accessing Files within Folders
//
// Use a key of the form [path]/[to]/[file]/[filename].[ext]
//
await blobs.WriteAsync("subdirectory/filename.ext", "text/plain", "Hello!");
Metadata and Enumeration
Enumeration is always full; the library will manage any continuation tokens (e.g. AWS S3, S3 compatible, Azure) and also recurse into subdirectories for file, CIFS, and NFS.
// Get BLOB metadata
BlobMetadata md = await _Blobs.GetMetadataAsync("key");
// Enumerate BLOBs
await foreach (BlobMetadata blob in _Blobs.EnumerateAsync())
Console.WriteLine(blob.Key + " " + blob.ContentLength + " folder? " + blob.IsFolder);
Enumeration filters are cloned internally so provider calls do not mutate caller-supplied filter instances. Object-storage providers use case-sensitive key matching; disk and CIFS use case-insensitive matching for compatibility with their typical filesystems.
Copying BLOBs from Repository to Repository
If you have multiple storage repositories and wish to move BLOBs from one repository to another, use the BlobCopy class (refer to the Test.Copy project for a full working example).
Thanks to @phpfui for contributing code and the idea for this enhancement!
// instantiate two BLOB clients
BlobCopy copy = new BlobCopy(from, to);
CopyStatistics stats = await copy.StartAsync();
/*
{
"Success": true,
"Time": {
"Start": "2021-12-22T18:44:42.9098249Z",
"End": "2021-12-22T18:44:42.9379215Z",
"TotalMs": 28.1
},
"ContinuationTokens": 0,
"BlobsEnumerated": 12,
"BytesEnumerated": 1371041,
"BlobsRead": 12,
"BytesRead": 1371041,
"BlobsWritten": 12,
"BytesWritten": 1371041,
"Keys": [
"filename.txt",
...
]
}
*/
BlobCopy.Start(...) remains available for compatibility and delegates to StartAsync(...). Copy now uses GetStreamAsync and stream writes where the provider supports them.
Bulk Operations
WriteManyAsync and EmptyAsync use bounded concurrency through BlobClientBase.MaxConcurrency, which defaults to 4.
blobs.MaxConcurrency = 8;
await blobs.WriteManyAsync(writes);
Version History
Refer to CHANGELOG.md for version history.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 is compatible. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- AWSSDK.S3 (>= 4.0.24)
- Blobject.Core (>= 5.0.19)
-
net10.0
- AWSSDK.S3 (>= 4.0.24)
- Blobject.Core (>= 5.0.19)
-
net8.0
- AWSSDK.S3 (>= 4.0.24)
- Blobject.Core (>= 5.0.19)
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 |
|---|---|---|
| 5.0.20 | 57 | 6/4/2026 |
| 5.0.19 | 45 | 6/4/2026 |
| 5.0.18 | 3,878 | 12/28/2025 |
| 5.0.15 | 382 | 12/16/2025 |
| 5.0.14 | 9,345 | 3/23/2025 |
| 5.0.12 | 572 | 3/8/2025 |
| 5.0.10 | 1,999 | 12/24/2024 |
| 5.0.8 | 1,739 | 8/28/2024 |
| 5.0.6 | 3,860 | 5/17/2024 |
| 5.0.5 | 222 | 5/17/2024 |
| 5.0.3 | 222 | 4/30/2024 |
| 5.0.2 | 223 | 4/30/2024 |
| 5.0.1 | 219 | 4/29/2024 |
Fix streaming reads, empty writes, filter handling, and shared bulk operations.