/// <summary> /// Handle /// </summary> /// <param name="command"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <CommandResponse> Handle(UploadAttachmentCommand command, CancellationToken cancellationToken) { CommandResponse response = new CommandResponse(); AttachmentModel uploadedAttachment = new AttachmentModel(); // prepare the upload string originalName = System.IO.Path.GetFileName(command.File.FileName); string extension = System.IO.Path.GetExtension(command.File.FileName).ToLower(); string storedAsFileName = $"{uploadedAttachment.Id}{extension}"; string fileFullPath = StoragePath.Combine("attachments", storedAsFileName); // upload string fullPath = await _storageService.UploadFile(command.File, fileFullPath); uploadedAttachment.FilePath = fullPath; // prepare response uploadedAttachment.FileName = storedAsFileName; uploadedAttachment.FileType = extension; uploadedAttachment.ContentType = command.File.ContentType; uploadedAttachment.OriginalFileName = originalName; uploadedAttachment.Name = originalName; uploadedAttachment.Description = $"Attachment {originalName}"; response.Resource = uploadedAttachment; return(response); }
/// <summary> /// Handle /// </summary> /// <param name="command"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <CommandResponse> Handle(UploadMultipleAttachmentCommand command, CancellationToken cancellationToken) { CommandResponse response = new CommandResponse() { UploadedAttachments = new List <AttachmentModel>() }; foreach (var commandFile in command.Files) { AttachmentModel attachment = new AttachmentModel(); // prepare the upload string originalName = System.IO.Path.GetFileName(commandFile.FileName); string extension = System.IO.Path.GetExtension(commandFile.FileName).ToLower(); string storedAsFileName = $"{attachment.Id}{extension}"; string fileFullPath = StoragePath.Combine("attachments", storedAsFileName); // upload string fullPath = await _storageService.UploadFile(commandFile, fileFullPath); attachment.FilePath = fullPath; // prepare response attachment.FileName = storedAsFileName; attachment.FileType = extension; attachment.ContentType = commandFile.ContentType; attachment.OriginalFileName = originalName; attachment.Name = originalName; attachment.Description = $"Attachment {originalName}"; response.UploadedAttachments.Add(attachment); } return(response); }