Filehook is a file attachment library for dotnet inspired by Paperclip.
https://www.myget.org/F/filehook/api/v3/index.json
public void ConfigureServices(IServiceCollection services)
{
services.AddFilehook(FileSystemConsts.FileSystemStorageName);
// TODO specify storage
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "./wwwroot/public")),
RequestPath = new PathString("/public")
});
}
Mark properties with special attributes:
public class Article
{
[HasId]
public int Id { get; set; }
[HasImageStyle("small", 0, 200)]
[HasImageStyle("large", 0, 300)]
public string CoverImageFileName { get; set; }
public string AttachmentFileName { get; set; }
}
The same using metadata:
public void ConfigureServices(IServiceCollection services)
{
services.AddFilehook(FileSystemConsts.FileSystemStorageName)
.AddMetadata(builder => {
builder.Entity<Article>(entity => {
entity.HasId(x => x.Id.ToString());
entity.HasName("MyArticle");
entity.Property(x => x.CoverImageFileName)
.HasName("FileName")
.HasImageStyle(new ImageStyle("small", new ImageResizeOptions { Height = 200 }))
.HasImageStyle(new ImageStyle("large", new ImageResizeOptions { Height = 300 }));
});
});
}
Filehook uses ImageSharp on module Filehook.Proccessors.Image.ImageSharpProccessor
to proccess your images that marked with [HasImageStyle]
attribute
The storage allows to save files to file system.
public void ConfigureServices(IServiceCollection services)
{
services.AddFilehook(FileSystemConsts.FileSystemStorageName)
.AddFileSystemStorage(options =>
{
options.BasePath = "./wwwroot";
options.CdnUrl = "http://localhost:5000";
});
}
Allows to store files on S3.
public void ConfigureServices(IServiceCollection services)
{
services.AddFilehook(S3Consts.S3StorageName)
.AddS3Storage(options =>
{
options.AccessKeyId = Configuration["Filehook:S3:AccessKeyId"];
options.SecretAccessKey = Configuration["Filehook:S3:SecretAccessKey"];
options.BucketName = Configuration["Filehook:S3:BucketName"];
options.Region = Configuration["Filehook:S3:Region"];
});
}
TODO
Default location template is :base/public/:objectClass/:propertyName/:objectId/:style/:filename
- Split file saving and url generation
- Validators ?
- Tests
The MIT License (MIT)