LiteX.Storage.Amazon
3.0.0
This client library enables working with the Amazon AWS S3 Blob service for storing binary data. Wrapper around the Amazon AWS S3 Blob to handle container instantiations for any type of application (ASP.NET Core, .Net Standard 2.x). A very simple .NET interface to blob storage and basic wrapper around the Amazon AWS S3 Storage API.
See the version list below for details.
Install-Package LiteX.Storage.Amazon -Version 3.0.0
dotnet add package LiteX.Storage.Amazon --version 3.0.0
<PackageReference Include="LiteX.Storage.Amazon" Version="3.0.0" />
paket add LiteX.Storage.Amazon --version 3.0.0
#r "nuget: LiteX.Storage.Amazon, 3.0.0"
// Install LiteX.Storage.Amazon as a Cake Addin
#addin nuget:?package=LiteX.Storage.Amazon&version=3.0.0
// Install LiteX.Storage.Amazon as a Cake Tool
#tool nuget:?package=LiteX.Storage.Amazon&version=3.0.0
LiteXStorage
Abstract interface to implement any kind of basic blob storage services (e.g. Azure, Amazon, Google, Local FileSystem) for any type of application (ASP.NET Core, .Net Standard 2.x).
Add a dependency
Nuget
Run the nuget command for installing the client as,
Install-Package LiteX.Storage.Core
Install-Package LiteX.Storage.Amazon
Configuration
AppSettings
{
//LiteX Amazon Storage settings
"AmazonBlobConfig": {
"AmazonAwsAccessKeyId": "--- REPLACE WITH YOUR AMAZON ACCESS KEY ID ---",
"AmazonAwsSecretAccessKey": "--- REPLACE WITH YOUR AMAZON SECRET ACCESS KEY ---",
"AmazonBucketName": "--- REPLACE WITH YOUR AZURE AMAZON BUCKET NAME ---"
}
}
Startup Configuration
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// 1. Use default configuration from appsettings.json's 'AmazonBlobConfig'
services.AddLiteXAmazonBlobService();
//OR
// 2. Load configuration settings using options.
services.AddLiteXAmazonBlobService(option =>
{
//option. = "";
});
//OR
// 3. Load configuration settings on your own.
// (e.g. appsettings, database, hardcoded)
var amazonBlobConfig = new AmazonBlobConfig();
services.AddLiteXAmazonBlobService(amazonBlobConfig);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
}
}
Usage
Controller or Business layer
/// <summary>
/// Customer controller
/// </summary>
public class CustomerController : Controller
{
#region Fields
private readonly IBlobService _blobService;
#endregion
#region Ctor
/// <summary>
/// Ctor
/// </summary>
/// <param name="blobService"></param>
public CustomerController(IBlobService blobService)
{
_blobService = blobService;
}
#endregion
#region Methods
/// <summary>
/// Create/Replace blob file
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public IActionResult UploadBlobFile(IFormFile file)
{
try
{
string blobName = file.FileName;
byte[] data = StreamToByteArray(file.OpenReadStream());
string contentType = file.ContentType;
bool isUploaded = _blobService.UploadBlob(blobName, data, contentType);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
/// <summary>
/// Get blob file data (bytes or stream)
/// </summary>
/// <param name="blobName"></param>
/// <returns></returns>
public IActionResult GetBlobFile(string blobName)
{
try
{
// get blob bytes
byte[] data = _blobService.GetBlob(blobName);
// get memeory stream
MemoryStream stream = _blobService.GetBlobStream(blobName);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
/// <summary>
/// Get blob url
/// </summary>
/// <param name="blobName"></param>
/// <returns></returns>
public IActionResult GetBlobUrl(string blobName)
{
try
{
string blobUrl = _blobService.GetBlobUrl(blobName);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
/// <summary>
/// Delete blob file
/// </summary>
/// <param name="blobName"></param>
/// <returns></returns>
public IActionResult DeleteBlobFile(string blobName)
{
try
{
bool isDeleted = _blobService.DeleteBlob(blobName);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
/// <summary>
/// Get blob metadata
/// </summary>
/// <param name="blobName"></param>
/// <returns></returns>
public IActionResult GetBlobMetadata(string blobName)
{
try
{
IDictionary<string, string> metadata = _blobService.GetBlobMetadata(blobName);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
/// <summary>
/// Set blob metadata
/// </summary>
/// <param name="blobName"></param>
/// <returns></returns>
public IActionResult SetBlobMetadata(string blobName)
{
try
{
IDictionary<string, string> metadata = new Dictionary<string, string>();
//list of metadata to update
//metadata.Add("", "");
bool isSet = _blobService.SetBlobMetadata(blobName, metadata);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
#endregion
#region Utilities
private IList<Customer> GetCustomers()
{
IList<Customer> customers = new List<Customer>();
customers.Add(new Customer() { Id = 1, Username = "ashish", Email = "toaashishpatel@outlook.com" });
return customers;
}
private Customer GetCustomerById(int id)
{
Customer customer = null;
customer = GetCustomers().ToList().FirstOrDefault(x => x.Id == id);
return customer;
}
public static byte[] StreamToByteArray(Stream input)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
#endregion
}
LiteXStorage
Abstract interface to implement any kind of basic blob storage services (e.g. Azure, Amazon, Google, Local FileSystem) for any type of application (ASP.NET Core, .Net Standard 2.x).
Add a dependency
Nuget
Run the nuget command for installing the client as,
Install-Package LiteX.Storage.Core
Install-Package LiteX.Storage.Amazon
Configuration
AppSettings
{
//LiteX Amazon Storage settings
"AmazonBlobConfig": {
"AmazonAwsAccessKeyId": "--- REPLACE WITH YOUR AMAZON ACCESS KEY ID ---",
"AmazonAwsSecretAccessKey": "--- REPLACE WITH YOUR AMAZON SECRET ACCESS KEY ---",
"AmazonBucketName": "--- REPLACE WITH YOUR AZURE AMAZON BUCKET NAME ---"
}
}
Startup Configuration
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// 1. Use default configuration from appsettings.json's 'AmazonBlobConfig'
services.AddLiteXAmazonBlobService();
//OR
// 2. Load configuration settings using options.
services.AddLiteXAmazonBlobService(option =>
{
//option. = "";
});
//OR
// 3. Load configuration settings on your own.
// (e.g. appsettings, database, hardcoded)
var amazonBlobConfig = new AmazonBlobConfig();
services.AddLiteXAmazonBlobService(amazonBlobConfig);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
}
}
Usage
Controller or Business layer
/// <summary>
/// Customer controller
/// </summary>
public class CustomerController : Controller
{
#region Fields
private readonly IBlobService _blobService;
#endregion
#region Ctor
/// <summary>
/// Ctor
/// </summary>
/// <param name="blobService"></param>
public CustomerController(IBlobService blobService)
{
_blobService = blobService;
}
#endregion
#region Methods
/// <summary>
/// Create/Replace blob file
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public IActionResult UploadBlobFile(IFormFile file)
{
try
{
string blobName = file.FileName;
byte[] data = StreamToByteArray(file.OpenReadStream());
string contentType = file.ContentType;
bool isUploaded = _blobService.UploadBlob(blobName, data, contentType);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
/// <summary>
/// Get blob file data (bytes or stream)
/// </summary>
/// <param name="blobName"></param>
/// <returns></returns>
public IActionResult GetBlobFile(string blobName)
{
try
{
// get blob bytes
byte[] data = _blobService.GetBlob(blobName);
// get memeory stream
MemoryStream stream = _blobService.GetBlobStream(blobName);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
/// <summary>
/// Get blob url
/// </summary>
/// <param name="blobName"></param>
/// <returns></returns>
public IActionResult GetBlobUrl(string blobName)
{
try
{
string blobUrl = _blobService.GetBlobUrl(blobName);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
/// <summary>
/// Delete blob file
/// </summary>
/// <param name="blobName"></param>
/// <returns></returns>
public IActionResult DeleteBlobFile(string blobName)
{
try
{
bool isDeleted = _blobService.DeleteBlob(blobName);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
/// <summary>
/// Get blob metadata
/// </summary>
/// <param name="blobName"></param>
/// <returns></returns>
public IActionResult GetBlobMetadata(string blobName)
{
try
{
IDictionary<string, string> metadata = _blobService.GetBlobMetadata(blobName);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
/// <summary>
/// Set blob metadata
/// </summary>
/// <param name="blobName"></param>
/// <returns></returns>
public IActionResult SetBlobMetadata(string blobName)
{
try
{
IDictionary<string, string> metadata = new Dictionary<string, string>();
//list of metadata to update
//metadata.Add("", "");
bool isSet = _blobService.SetBlobMetadata(blobName, metadata);
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok();
}
#endregion
#region Utilities
private IList<Customer> GetCustomers()
{
IList<Customer> customers = new List<Customer>();
customers.Add(new Customer() { Id = 1, Username = "ashish", Email = "toaashishpatel@outlook.com" });
return customers;
}
private Customer GetCustomerById(int id)
{
Customer customer = null;
customer = GetCustomers().ToList().FirstOrDefault(x => x.Id == id);
return customer;
}
public static byte[] StreamToByteArray(Stream input)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
#endregion
}
Release Notes
Advanced configuration for ASP.NET Core application.
Dependencies
-
.NETStandard 2.0
- AWSSDK.Core (>= 3.3.22.1)
- AWSSDK.S3 (>= 3.3.18.2)
- LiteX.Storage.Core (>= 3.0.0)
- Microsoft.Extensions.Configuration (>= 2.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection (>= 2.0.0)
Used By
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version History
Version | Downloads | Last updated |
---|---|---|
8.0.0 | 292 | 1/1/2021 |
7.1.0 | 887 | 4/3/2020 |
7.0.0 | 5,382 | 8/4/2019 |
6.4.0 | 1,751 | 1/31/2019 |
6.3.0 | 3,534 | 11/15/2018 |
6.2.0 | 413 | 10/10/2018 |
6.1.2 | 414 | 9/13/2018 |
6.1.1 | 408 | 8/27/2018 |
6.0.0 | 454 | 7/22/2018 |
5.0.0 | 501 | 6/27/2018 |
4.1.0 | 469 | 6/16/2018 |
4.0.0 | 537 | 6/2/2018 |
3.0.0 | 562 | 5/7/2018 |
2.0.0 | 607 | 4/25/2018 |
1.0.0 | 653 | 4/22/2018 |