rknyryn.LocalFileStorage
3.2.0
dotnet add package rknyryn.LocalFileStorage --version 3.2.0
NuGet\Install-Package rknyryn.LocalFileStorage -Version 3.2.0
<PackageReference Include="rknyryn.LocalFileStorage" Version="3.2.0" />
paket add rknyryn.LocalFileStorage --version 3.2.0
#r "nuget: rknyryn.LocalFileStorage, 3.2.0"
// 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.
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 | Versions 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. |
-
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.