media upload
This commit is contained in:
parent
befaa207d7
commit
0d7da2ea85
33 changed files with 257 additions and 353 deletions
|
@ -0,0 +1,5 @@
|
|||
using MediatR;
|
||||
|
||||
namespace Femto.Modules.Media.Contracts.SaveFile;
|
||||
|
||||
public record SaveFileCommand(Stream Data, string ContentType, long? ContentLength) : IRequest<Guid>;
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue