BlobHelper
BlobHelper is a common, consistent storage interface for Microsoft Azure, Amazon S3, S3 compatible storage (i.e. Minio, Less3), Kvpbase, and local filesystem written in C#.
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
Many thanks to @phpfui for adding the original code for BLOB copy functionality!
New in v2.2.0
- BlobCopy class to copy objects from one repository to another (thank you @phpfui!)
Example Project
Refer to the Test
project for exercising the library.
Getting Started - AWS S3
using BlobHelper;
AwsSettings settings = new AwsSettings(
accessKey,
secretKey,
AwsRegion.USWest1,
bucket);
Blobs blobs = new Blobs(settings);
Getting Started - AWS S3 Compatible Storage (Minio, Less3, etc)
using BlobHelper;
AwsSettings settings = new AwsSettings(
endpoint, // http://localhost:8000/
true, // enable or disable SSL
accessKey,
secretKey,
AwsRegion.USWest1,
bucket,
baseUrl // i.e. http://localhost:8000/{bucket}/{key}
);
Blobs blobs = new Blobs(settings);
Getting Started - Azure
using BlobHelper;
AzureSettings settings = new AzureSettings(
accountName,
accessKey,
"https://[accountName].blob.core.windows.net/",
containerName);
Blobs blobs = new Blobs(settings);
Getting Started - Komodo
using BlobHelper;
KomodoSettings settings = new KomodoSettings(
"http://localhost:9090/",
indexGuid,
apiKey);
Blobs blobs = new Blobs(settings);
Getting Started - Kvpbase
using BlobHelper;
KvpbaseSettings settings = new KvpbaseSettings(
"http://localhost:8000/",
userGuid,
containerName,
apiKey);
Blobs blobs = new Blobs(settings);
Getting Started - Disk
using BlobHelper;
DiskSettings settings = new DiskSettings("blobs");
Blobs blobs = new Blobs(settings);
Getting Started (Byte Arrays for Smaller Objects)
await blobs.Write("test", "text/plain", "This is some data"); // throws IOException
byte[] data = await blobs.Get("test"); // throws IOException
bool exists = await blobs.Exists("test");
await blobs.Delete("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.Write("key", "content-type", contentLength, fs); // throws IOException
}
// Downloading to a stream
BlobData blob = await _Blobs.GetStream(key);
// read blob.ContentLength bytes from blob.Data
Metadata and Enumeration
// Get BLOB metadata
BlobMetadata md = await _Blobs.GetMetadata("key");
// Enumerate BLOBs
EnumerationResult result = await _Blobs.Enumerate();
// list of BlobMetadata contained in result.Blobs
// continuation token in result.NextContinuationToken
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!
Blobs from = new Blobs(new DiskSettings("./disk1/")); // assume some files are here
Blobs to = new Blobs(new DiskSettings("./disk2/"));
BlobCopy copy = new BlobCopy(from, to);
CopyStatistics stats = copy.Start();
/*
{
"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",
...
]
}
*/
Version History
Refer to CHANGELOG.md for version history.