mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
Integrate SeaweedFS for S3-compatible file storage and photo upload (#254)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using Domain.Entities;
|
||||
using Features.ImageUploads.Repository;
|
||||
using Infrastructure.FileUpload;
|
||||
using MediatR;
|
||||
|
||||
namespace Features.ImageUploads.Commands.UploadPhoto;
|
||||
|
||||
/// <summary>Handles <see cref="UploadPhotoCommand" />.</summary>
|
||||
public class UploadPhotoHandler(
|
||||
IFileStorageProvider fileStorageProvider,
|
||||
IPhotoUploadRepository photoUploadRepository
|
||||
) : IRequestHandler<UploadPhotoCommand, Guid>
|
||||
{
|
||||
public async Task<Guid> Handle(UploadPhotoCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
Guid photoId = Guid.NewGuid();
|
||||
string key = $"{request.Key}/{photoId}";
|
||||
|
||||
await using Stream stream = request.File.OpenReadStream();
|
||||
|
||||
await fileStorageProvider.UploadAsync(
|
||||
key,
|
||||
stream,
|
||||
request.File.ContentType,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
Photo photo = new() { Hyperlink = key, UploadedById = request.UploadedById };
|
||||
|
||||
await photoUploadRepository.CreateAsync(photo, cancellationToken);
|
||||
|
||||
return photoId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user