public async Task <Response <UploadFileResponseMessage> > UploadAsync(UploadFileRequestMessage requestMessage)
        {
            var response = Response <UploadFileResponseMessage> .Create(new UploadFileResponseMessage(Guid.NewGuid()));

            foreach (var file in requestMessage.Files)
            {
                if (string.IsNullOrEmpty(file.FolderName))
                {
                    return(response.WithBusinessError(nameof(file.FolderName), "O nome do folder é obrigatório."));
                }

                var bytes = Convert.FromBase64String(Regex.Replace(file.Base64, "data:.*.base64,", ""));

                var memoryStream = new MemoryStream(bytes, 0, bytes.Length);

                await TransferUtility.UploadAsync(memoryStream, $"{Options.Value.StorageAws.BucketName}/{file.FolderName}", file.Name);

                response.Data.Value.Files.Add(new UploadFileResponseMessage.FileResponseMessage
                {
                    Name          = file.Name,
                    UploadFileURL = $"{Options.Value.StorageAws.BaseUrl}/{file.FolderName}/{file.Name}"
                });
            }

            return(response);
        }
Esempio n. 2
0
 public async Task <IActionResult> UploadAsync([FromBody] UploadFileRequestMessage requestMessage)
 => await TryAsync(() => StorageExternalService.UploadAsync(requestMessage));