rknyryn.LocalFileStorage 3.2.0

dotnet add package rknyryn.LocalFileStorage --version 3.2.0
NuGet\Install-Package rknyryn.LocalFileStorage -Version 3.2.0
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="rknyryn.LocalFileStorage" Version="3.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add rknyryn.LocalFileStorage --version 3.2.0
#r "nuget: rknyryn.LocalFileStorage, 3.2.0"
#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 rknyryn.LocalFileStorage as a Cake Addin
#addin nuget:?package=rknyryn.LocalFileStorage&version=3.2.0

// Install rknyryn.LocalFileStorage as a Cake Tool
#tool nuget:?package=rknyryn.LocalFileStorage&version=3.2.0

Local File Storage

Local File Storage is a NuGet package developed with .NET. This package basically performs file writing and deletion operations on the local disk. Developers can use this package for file operations in their small or medium-sized projects.

License: MIT

Getting started

Install the package

Install the Local File Storage library for .NET. Using the NuGet package manager console within Visual Studio run the following command:

Install-Package rknyryn.LocalFileStorage

Or using the .net core CLI from a terminal window:

dotnet add package rknyryn.LocalFileStorage

Configuration

You can get IFileStorage instance via dependency injection, you need add to services.

builder.Services.AddFileStorageServices();

or you can configure

builder.Services.AddFileStorageServices(options =>
{
    options.BaseFolderPath = Path.Combine("uploaded", "files");
    options.GlobalFileExtensionFilter = [".pdf", ".png"];
    options.GenerateFileName = false; //default true
});

BaseFolderPath specifies the root directory where uploaded files will be stored within the file system. All uploaded files will be organized relative to this base folder.

GlobalFileExtensionFilter is a setting that defines a global filter for file extensions. It determines which file types are allowed to be uploaded and stored within the system. Only files with extensions specified in this filter will be accepted.

Usage

Example Response

{
  "fileName": "combinepdf.pdf",
  "fileNameGenerated": "20240311_e67a0_combinepdf-912.pdf",
  "filePath": "uploaded/files/documents/20240311_e67a0_combinepdf-912.pdf",
  "fullPath": "/Users/kaanyarayan/Projects/CookieAuthenticationDemo/uploaded/files/documents/20240311_e67a0_combinepdf-912.pdf",
  "contentType": "application/pdf"
}

Controller-based API Example

[ApiController]
[Route("[controller]")]
public class FileStorageController : ControllerBase
{
    private readonly IFileStorage _fileStorage;

    public FileStorageController(IFileStorage fileStorage)
    {
        _fileStorage = fileStorage;
    }

    [HttpPost("uploadFile")]
    public FileUploadResult UploadFile(IFormFile uploadedFile)
    {
        FileUploadResult fileUploadResult = _fileStorage.UploadFile(file: uploadedFile, directoryPath: "documents");
        // FileUploadResult fileUploadResult = fileStorage.UploadFile(file: uploadedFile, directoryPath: "documents", extensionFilter: [".jpg"]);
        // FileUploadResult fileUploadResult = fileStorage.UploadFile(file: uploadedFile, directoryPath: "documents", extensionFilter: [".jpg"], includeGlobalFileExtensionFilter: false);

        return fileUploadResult;
    }

    [HttpGet("downloadFile")]
    public FileStreamResult DownloadFile(string filePath)
    {
        var stream = _fileStorage.GetFile(filePath: filePath);

        return new FileStreamResult(stream, "application/octet-stream")
        {
            FileDownloadName = Path.GetFileName(filePath),
            EnableRangeProcessing = true
        };
    }

    [HttpPost("deleteFile")]
    public string DeleteFile(string filePath)
    {
        _fileStorage.DeleteFile(filePath: filePath);

        return filePath;
    }
}

Feedback

Local File Storage is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

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
3.2.0 103 4/16/2024
3.1.0 131 3/27/2024
3.0.0 133 3/27/2024
2.0.1 114 3/26/2024
2.0.0 165 3/11/2024
1.1.0 210 3/4/2024
1.0.2 219 2/21/2024
1.0.1 204 2/21/2024
1.0.0 172 2/21/2024