Scsl.S3 8.0.12

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Scsl.S3 --version 8.0.12                
NuGet\Install-Package Scsl.S3 -Version 8.0.12                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Scsl.S3" Version="8.0.12" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Scsl.S3 --version 8.0.12                
#r "nuget: Scsl.S3, 8.0.12"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Scsl.S3 as a Cake Addin
#addin nuget:?package=Scsl.S3&version=8.0.12

// Install Scsl.S3 as a Cake Tool
#tool nuget:?package=Scsl.S3&version=8.0.12                

Scsl.S3

This lightweight library provides seamless access to Cloudflare R2 Object Storage, enabling you to efficiently upload (Put) and delete objects.

Installation

dotnet add package Scsl.S3 
dotnet add package Scsl.S3 --version <version>

Using the Cloudflare R2 Library: A Quick Guide

Program.cs

using Scsl.S3;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();

builder.Services.Configure<R2Options>(builder.Configuration.GetSection(R2Options.Name));
builder.Services.AddScoped<IR2Client, R2Client>();

appsettings.json

{
    "R2Options":
    {
      "PublicEndpoint": "https://sub.domain.tld",
      "BucketName": "string",
      "AccessKeyId": "string",
      "SecretAccessKey": "string",
      "Endpoint": "https://<ACCOUNT_ID>.r2.cloudflarestorage.com/"
    }
}

FileUploadFromModel.cs

public class FileuploadFromModel
{
    [Required]
    [Display(Name="File"])
    public IFormFile FormFile {get; set;}
}

Constructor

private readonly IR2Cleint _cleint;
private readonly IOptions<R2Options> _options
    
public Constructor(IR2Client client, IOptions<R2Options> options)
{
   _client = client;
   _options = options;
}

PutObject using MemoryStream

public async Task<IActionResult> PutObject(FileUploadFromModel file)
{
    using var stream = new MemoryStream();
    await file.FormFile.CopyToAsync(stream);
    var results = await _client.PutObject(stream, _options.Value.BucketName, "Upload/file.ext");
    if(!results.Succeeded) return BadRequest(new Json(results.Errors.ToList());
    
    return HttpStatusCode.Created;
}

DeleteObject

public async Task<IActionResult> DeleteObject(string file)
{
    var results = await _client.DeleteObject(_options.Value.BucketName, file);
    if(!results.Succeeded) return BadRequest(new Json(results.Errors.ToList());
    
    return HttpStatusCode.NoContent;
}

R3ClientResult response

{
  "Success": bool,
  "Errors": [
    { "Code": "string", "Description":  "string" }
  ]
}
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
8.0.14 77 12/16/2024
8.0.13 88 12/5/2024
8.0.12 76 12/2/2024