media upload

This commit is contained in:
john 2025-05-04 21:46:24 +02:00
parent befaa207d7
commit 0d7da2ea85
33 changed files with 257 additions and 353 deletions

View file

@ -0,0 +1,5 @@
using MediatR;
namespace Femto.Modules.Media.Contracts.SaveFile;
public record SaveFileCommand(Stream Data, string ContentType, long? ContentLength) : IRequest<Guid>;

View file

@ -0,0 +1,18 @@
using Femto.Modules.Media.Data;
using Femto.Modules.Media.Infrastructure;
using MediatR;
namespace Femto.Modules.Media.Contracts.SaveFile;
internal class SaveFileCommandHandler(IStorageProvider storage, MediaContext context)
: IRequestHandler<SaveFileCommand, Guid>
{
public async Task<Guid> Handle(SaveFileCommand command, CancellationToken cancellationToken)
{
var id = Guid.CreateVersion7();
await storage.SaveBlob(id.ToString(), command.Data);
await context.AddAsync(new SavedBlob(id, command.ContentType, command.ContentLength), cancellationToken);
await context.SaveChangesAsync(cancellationToken);
return id;
}
}