public override async Task FinishUploadAsync(UploadRequestFinish model, string blobName, CancellationToken token) { if (model is FinishChatUpload chatModel) { var userId = _userManager.GetLongUserId(User); if (userId == chatModel.OtherUser) { throw new ArgumentException(); } var command = new SendChatFileMessageCommand(blobName, userId, new[] { chatModel.OtherUser }); await _commandBus.DispatchAsync(command, token); } }
public async Task <ActionResult <UploadStartResponse> > UploadSingleFileAsync( [FromForm] long otherUser, [Required] IFormFile file, CancellationToken token) { var extension = Path.GetExtension(file.FileName); var userId = _userManager.GetLongUserId(User); if (!GetSupportedExtensions().Contains(extension, StringComparer.OrdinalIgnoreCase)) { throw new ArgumentException(); } var blobName = BlobFileName(Guid.NewGuid(), file.FileName); await BlobProvider.UploadStreamAsync(blobName, file.OpenReadStream(), token : token); var command = new SendChatFileMessageCommand(blobName, userId, new[] { otherUser }); await _commandBus.DispatchAsync(command, token); return(new UploadStartResponse(blobName)); }