LiteX.Storage.Core 2.0.0

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).

There is a newer version of this package available.
See the version list below for details.
Install-Package LiteX.Storage.Core -Version 2.0.0
dotnet add package LiteX.Storage.Core --version 2.0.0
<PackageReference Include="LiteX.Storage.Core" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LiteX.Storage.Core --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.Azure
  • Install-Package LiteX.Storage.Amazon
  • Install-Package LiteX.Storage.Google //NOT TESTED THOROUGHLY
  • Install-Package LiteX.Storage.Kvpbase //NOT TESTED THOROUGHLY
  • Install-Package LiteX.Storage.Local //NOT TESTED THOROUGHLY

Configuration

AppSettings

{
  //LiteX Azure Storage settings
  "AzureBlobConfig": {
    "AzureBlobStorageConnectionString": "--- REPLACE WITH YOUR AZURE CONNECTION STRING ---",
    "AzureBlobStorageContainerName": "--- REPLACE WITH YOUR AZURE CONTAINER NAME ---",
    "AzureBlobStorageEndPoint": "--- REPLACE WITH YOUR AZURE END POINT ---"
  },

  //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 ---"
  },

  //LiteX Google Storage settings
  "GoogleCloudBlobConfig": {
    "GoogleProjectId": "--- REPLACE WITH YOUR GOOGLE PROJECT ID ---",
    "GoogleJsonAuthPath": "--- REPLACE WITH YOUR GOOGLE JSON AUTH PATH ---",
    "GoogleBucketName": "--- REPLACE WITH YOUR GOOGLE BUCKET NAME ---"
  },

  //LiteX Kvpbase Storage settings
  "KvpbaseBlobConfig": {
    "KvpbaseApiKey": "--- REPLACE WITH YOUR KVPBASE API KEY ---",
    "KvpbaseContainer": "--- REPLACE WITH YOUR KVPBASE CONTAINER ---",
    "KvpbaseEndpoint": "--- REPLACE WITH YOUR KVPBASE END POINT ---",
    "KvpbaseUserGuid": "--- REPLACE WITH YOUR KVPBASE USERGUID ---"
  },

  //LiteX Local File System Storage settings
  "FileSystemBlobConfig": {
    "Directory": "--- REPLACE WITH YOUR LOCAL FILE SYSTEM DIRECTORY ---"
  }
}

Startup Configuration

public class Startup
{
    public IConfiguration configuration { get; }

    public Startup(IConfiguration configuration)
    {
        this.configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        #region LiteX Storage

        // blob storage (use one of below)

        #region LiteX Storage (Azure)

        services.AddLiteXAzureBlobService(configuration);

        // OR
        // load configuration settings on your own.
        // from appsettings, database, hardcoded etc.
        var azureBlobConfig = new AzureBlobConfig();
        services.AddLiteXAzureBlobService(configuration, azureBlobConfig);

        #endregion

        #region LiteX Storage (Amazon)

        services.AddLiteXAmazonBlobService(configuration);

        // OR
        // load configuration settings on your own.
        // from appsettings, database, hardcoded etc.
        var amazonBlobConfig = new AmazonBlobConfig();
        services.AddLiteXAmazonBlobService(configuration, amazonBlobConfig);

        #endregion

        #region LiteX Storage (Google)

        services.AddLiteXGoogleCloudBlobService(configuration);

        // OR
        // load configuration settings on your own.
        // from appsettings, database, hardcoded etc.
        var googleCloudBlobConfig = new GoogleCloudBlobConfig();
        services.AddLiteXGoogleCloudBlobService(configuration, googleCloudBlobConfig);

        #endregion

        #region LiteX Storage (Kvpbase)

        services.AddLiteXKvpbaseBlobService(configuration);

        // OR
        // load configuration settings on your own.
        // from appsettings, database, hardcoded etc.
        var kvpbaseBlobConfig = new KvpbaseBlobConfig();
        services.AddLiteXKvpbaseBlobService(configuration, kvpbaseBlobConfig);

        #endregion

        #region LiteX Storage (FileSystem-Local)

        services.AddLiteXFileSystemBlobService(configuration);

        // OR
        // load configuration settings on your own.
        // from appsettings, database, hardcoded etc.
        var fileSystemBlobConfig = new FileSystemBlobConfig();
        services.AddLiteXFileSystemBlobService(configuration, fileSystemBlobConfig);

        #endregion

        #endregion
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {

    }
}

Usage

public class CustomerController : Controller
{
    private readonly IBlobService _blobService;

    public CustomerController(IBlobService blobService)
    {
        _blobService = blobService;
    }

    #region Methods

    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();
    }

    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();
    }

    public IActionResult GetBlobUrl(string blobName)
    {
        try
        {
            string blobUrl = _blobService.GetBlobUrl(blobName);
        }
        catch (Exception ex)
        {
            return BadRequest(ex);
        }
        return Ok();
    }

    public IActionResult DeleteBlobFile(string blobName)
    {
        try
        {
            bool isDeleted = _blobService.DeleteBlob(blobName);
        }
        catch (Exception ex)
        {
            return BadRequest(ex);
        }
        return Ok();
    }

    public IActionResult GetBlobMetadata(string blobName)
    {
        try
        {
            IDictionary<string, string> metadata = _blobService.GetBlobMetadata(blobName);
        }
        catch (Exception ex)
        {
            return BadRequest(ex);
        }
        return Ok();
    }

    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.Azure
  • Install-Package LiteX.Storage.Amazon
  • Install-Package LiteX.Storage.Google //NOT TESTED THOROUGHLY
  • Install-Package LiteX.Storage.Kvpbase //NOT TESTED THOROUGHLY
  • Install-Package LiteX.Storage.Local //NOT TESTED THOROUGHLY

Configuration

AppSettings

{
  //LiteX Azure Storage settings
  "AzureBlobConfig": {
    "AzureBlobStorageConnectionString": "--- REPLACE WITH YOUR AZURE CONNECTION STRING ---",
    "AzureBlobStorageContainerName": "--- REPLACE WITH YOUR AZURE CONTAINER NAME ---",
    "AzureBlobStorageEndPoint": "--- REPLACE WITH YOUR AZURE END POINT ---"
  },

  //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 ---"
  },

  //LiteX Google Storage settings
  "GoogleCloudBlobConfig": {
    "GoogleProjectId": "--- REPLACE WITH YOUR GOOGLE PROJECT ID ---",
    "GoogleJsonAuthPath": "--- REPLACE WITH YOUR GOOGLE JSON AUTH PATH ---",
    "GoogleBucketName": "--- REPLACE WITH YOUR GOOGLE BUCKET NAME ---"
  },

  //LiteX Kvpbase Storage settings
  "KvpbaseBlobConfig": {
    "KvpbaseApiKey": "--- REPLACE WITH YOUR KVPBASE API KEY ---",
    "KvpbaseContainer": "--- REPLACE WITH YOUR KVPBASE CONTAINER ---",
    "KvpbaseEndpoint": "--- REPLACE WITH YOUR KVPBASE END POINT ---",
    "KvpbaseUserGuid": "--- REPLACE WITH YOUR KVPBASE USERGUID ---"
  },

  //LiteX Local File System Storage settings
  "FileSystemBlobConfig": {
    "Directory": "--- REPLACE WITH YOUR LOCAL FILE SYSTEM DIRECTORY ---"
  }
}

Startup Configuration

public class Startup
{
    public IConfiguration configuration { get; }

    public Startup(IConfiguration configuration)
    {
        this.configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        #region LiteX Storage

        // blob storage (use one of below)

        #region LiteX Storage (Azure)

        services.AddLiteXAzureBlobService(configuration);

        // OR
        // load configuration settings on your own.
        // from appsettings, database, hardcoded etc.
        var azureBlobConfig = new AzureBlobConfig();
        services.AddLiteXAzureBlobService(configuration, azureBlobConfig);

        #endregion

        #region LiteX Storage (Amazon)

        services.AddLiteXAmazonBlobService(configuration);

        // OR
        // load configuration settings on your own.
        // from appsettings, database, hardcoded etc.
        var amazonBlobConfig = new AmazonBlobConfig();
        services.AddLiteXAmazonBlobService(configuration, amazonBlobConfig);

        #endregion

        #region LiteX Storage (Google)

        services.AddLiteXGoogleCloudBlobService(configuration);

        // OR
        // load configuration settings on your own.
        // from appsettings, database, hardcoded etc.
        var googleCloudBlobConfig = new GoogleCloudBlobConfig();
        services.AddLiteXGoogleCloudBlobService(configuration, googleCloudBlobConfig);

        #endregion

        #region LiteX Storage (Kvpbase)

        services.AddLiteXKvpbaseBlobService(configuration);

        // OR
        // load configuration settings on your own.
        // from appsettings, database, hardcoded etc.
        var kvpbaseBlobConfig = new KvpbaseBlobConfig();
        services.AddLiteXKvpbaseBlobService(configuration, kvpbaseBlobConfig);

        #endregion

        #region LiteX Storage (FileSystem-Local)

        services.AddLiteXFileSystemBlobService(configuration);

        // OR
        // load configuration settings on your own.
        // from appsettings, database, hardcoded etc.
        var fileSystemBlobConfig = new FileSystemBlobConfig();
        services.AddLiteXFileSystemBlobService(configuration, fileSystemBlobConfig);

        #endregion

        #endregion
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {

    }
}

Usage

public class CustomerController : Controller
{
    private readonly IBlobService _blobService;

    public CustomerController(IBlobService blobService)
    {
        _blobService = blobService;
    }

    #region Methods

    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();
    }

    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();
    }

    public IActionResult GetBlobUrl(string blobName)
    {
        try
        {
            string blobUrl = _blobService.GetBlobUrl(blobName);
        }
        catch (Exception ex)
        {
            return BadRequest(ex);
        }
        return Ok();
    }

    public IActionResult DeleteBlobFile(string blobName)
    {
        try
        {
            bool isDeleted = _blobService.DeleteBlob(blobName);
        }
        catch (Exception ex)
        {
            return BadRequest(ex);
        }
        return Ok();
    }

    public IActionResult GetBlobMetadata(string blobName)
    {
        try
        {
            IDictionary<string, string> metadata = _blobService.GetBlobMetadata(blobName);
        }
        catch (Exception ex)
        {
            return BadRequest(ex);
        }
        return Ok();
    }

    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

Abstract interface to implement any kind of basic blob storage services (e.g. Azure, Amazon, Google, Local FileSystem)

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
6.3.0 1,306 11/15/2018
6.2.0 191 10/10/2018
6.1.0 385 8/26/2018
6.0.0 167 7/22/2018
5.0.0 195 6/27/2018
4.0.0 191 6/2/2018
3.0.0 167 5/7/2018
2.0.0 224 4/25/2018
1.0.0 240 4/21/2018
Show less