Azure Blob storage is Microsoft's object storage solution for the cloud. Blob storage is optimized for storing massive amounts of unstructured data. Unstructured data is data that doesn't adhere to a particular data model or definition, such as text or binary data.
About Blob storage Blob storage is designed for:
- Serving images or documents directly to a browser.
- Storing files for distributed access.
- Streaming video and audio.
- Writing to log files.
- Storing data for backup and restore, disaster recovery, and archiving.
- Storing data for analysis by an on-premises or Azure-hosted service.
Cloud Storage Abstraction is a small dll ( on the next iteration, it will be a nuget package) that provides a robust and reusable implementations.
With this package we standardize the usage and implementation of Azure Storage Blobs in all your code.
With this implementation you have both publish and subscriber clients available at one sight.
- Create Container
- Upload Blob
- Get list of blobs
- Get concrete blob
- Delete blob
At this point, we have to use this project like dll or directly on our production projects.
On next releases, we transform the solution into nuget.
- Newtonsoft
- Azure.Storage.Blob v12
- .Net 6.0
- System.Text.Json
git clone https://github.com/ERNI-Academy/assets-cloud-storage-abstraction.git
That contract contains all methods to manage a default CRUD.
public interface IBlobContainerClient
{
string GetConnectionString();
Task<Azure.Storage.Blobs.BlobContainerClient> CreateContainerIfNotExist(string name = "");
Task<string> UploadBlob(string id, object blob, string containerName);
Task<object> Get(Guid id, string containerId);
IEnumerable<object> Get(string containerId);
Task<bool> RemoveBlob(Guid id, string containerId);
}
That is the main implementation. It is the client to manage the CRUD operations with a concrete blob container.
public class BlobContainerClient : ContainerClientBase, IBlobContainerClient
{
private BlobServiceClient serviceClient;
public BlobContainerClient(IContainerServiceConfig config) : base(config){}
...
}
That contract specify the only way to assign a connectionstring to the BlobContainerClient
public interface IContainerServiceConfig
{
string GetConnectionString();
}
That implementation has the purpose to be used only to development environments. If you are developing and you want to use the local emulator, you could use that implementation. but take care, that approach never can be used on production
public class ContainerServiceDevelopmentConfig : IContainerServiceConfig
{
public string GetConnectionString()
{
return "UseDevelopmentStorage=true";
}
}
- the interface IContainerServiceConfig has a default implementation that is forbidden use it on production. ALWAYS RETURN a connection string for the Azure Storage Emulator.
- You should implement your own class where you could manage your proper connectionstring
In order to run this sample, you need to have Azure Blob Storage Emulator
IContainerServiceConfig config = new ContainerServiceDevelopmentConfig();
Console.WriteLine($"ConnectionString used: {config.GetConnectionString()}");
Console.WriteLine("first sample about upload an object");
IBlobContainerClient blobClient = new BlobContainerClient(config);
var obj = new { name = "Smith", age = 38 };
Guid id = Guid.NewGuid();
string containerName = "localcontainer";
Console.WriteLine($"object used: {obj}");
var blobLink = blobClient.UploadBlob(id.ToString(), obj, containerName).Result;
Console.WriteLine($"Http code response: {blobLink}");
- take care about that sample are instances directly. In general situation, we should use DI.
Please see our Contribution Guide to learn how to contribute.
(LICENSE) Β© 2022 ERNI - Swiss Software Engineering
Please see our Code of Conduct
π§ esp-services@betterask.erni
Manu Delgado - @mdelgadodiaz83 - mdelgadodiaz83@gmail.com
Thanks goes to these wonderful people (emoji key):
omaramalfi π» π π π¨ π€ π§ |
mdelgadodiaz83-erni π» π π π¨ π€ π§ |
This project follows the all-contributors specification. Contributions of any kind welcome!