https://github.com/simplify9/cloudfiles
Abstraction of Amazon S3 SDK for the needed file operations, utilizing streams, and Asp.Net Core dependency injection
https://github.com/simplify9/cloudfiles
Last synced: 10 months ago
JSON representation
Abstraction of Amazon S3 SDK for the needed file operations, utilizing streams, and Asp.Net Core dependency injection
- Host: GitHub
- URL: https://github.com/simplify9/cloudfiles
- Owner: simplify9
- License: mit
- Created: 2020-05-30T11:56:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-08-03T08:38:43.000Z (10 months ago)
- Last Synced: 2025-08-08T08:52:52.186Z (10 months ago)
- Language: C#
- Homepage:
- Size: 132 KB
- Stars: 7
- Watchers: 4
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README

| **Package** | **Version** |
| :----------------:|:----------------------:|
| ``SimplyWorks.HttpExtensions``||
[](https://opensource.org/licenses/MIT) 
## Introduction
*CloudFiles* is a minimalist library that abstracts the [Amazon S3](https://aws.amazon.com/s3/) SDK. It has the core needed from a file-uploading library without the hassle of going through mountains of documentation.
*CloudFiles* has extensions to integrate it into the ASP dotnet core dependency injection. It covers multiple ways to upload data, including opening writable streams or simply uploading a file's data from [IFormFile](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.iformfile?view=aspnetcore-3.1) or similar.
## Installation
There are two [NuGet](https://www.nuget.org/packages/SimplyWorks.CloudFiles/) packages for Cloudfiles, one for being the actual service, installed with:
`dotnet add package Simplyworks.CloudFiles`
While the other is used to integrate it into the dependency injection, with:
`dotnet add package Simplyworks.CloudFiles.Extensions`
## Getting Started
To register *Cloudfiles*, use the service collection extension method. Add *Cloudfiles* to your startup file and pass the configuration in one of these two ways:
1. Configure your details in the **AppSettings.json** file and then call **.AddCloudFiles()** in your Startup file.
Here's how:
```json
"CloudFiles": {
"AccessKeyId": "",
"SecretAccessKey": "",
"BucketName": "",
"ServiceUrl": ""
},
```
2. Use the **AddCloudFiles** function in your Startup file and specify your parameters like so:
```csharp
.AddCloudFiles( config =>
config.AccessKeyId = ""
config.SecretAccessKey = "";
config.ServiceUrl = "";
config.BucketName = "";
)
```
Then simply add the *ICoudFilesService* interface (from [PrimitiveTypes](https://github.com/simplify9/primitivetypes)) in the constructor of a controller for it to be injected, then use the functions provided!
## Examples
### Reading from Cloud bucket example:
We initialize this function with its corresponding primitive type, and it then reads a file from the bucket and writes it onto the local disk.
``` C#
async public Task TestOpenReadAcync()
{
var cloudFiles = server.Host.Services.GetService();
using var stream = await cloudFiles.OpenReadAsync("test/TestWriteAcync.txt");
using var diskFile = File.OpenWrite(@"c:\temp\sample.txt");
await stream.CopyToAsync(diskFile);
}
```
### CloudFiles used in an ASP Controller endpoint:
```C#
[HttpPost]
[Route("{**directory}")]
public async Task UploadBlobToCloud([FromRoute]string directory, [FromForm]IFormFile file)
{
string directoryPath = directory.EndsWith('/') ? directory : directory + '/';
if(_contentTypeProvider.TryGetContentType(file.FileName, out string mimeType))
{
var blob = await cloudFilesService.WriteAsync(file.OpenReadStream(), new PrimitiveTypes.WriteFileSettings
{
ContentType = mimeType,
Key = directoryPath + file.FileName,
CloseInputStream = false,
Public = true,
Metadata = new Dictionary()
});
return Ok(blob.Location);
} throw new Exception("Invalid form file");
}
```
## Getting support 👷
If you encounter any bugs, don't hesitate to submit an [issue](https://github.com/simplify9/CloudFiles/issues). We'll get back to you promptly!