private async Task UploadFileToStorage(Stream fileStream, string fileName) { var bucketName = _config.BucketName; var bucketExists = await _bucketRepository.DoesS3BucketExist(bucketName); if (bucketExists == false) { var response = await _bucketRepository.CreateBucket(bucketName); if (response.IsFailure) { Console.WriteLine(response.Error); return; } } var fileData = new FileData { FileName = fileName }; fileData.Stream = new MemoryStream(); fileStream.CopyTo(fileData.Stream); var uploadResponse = await _fileRepository.UploadFiles(bucketName, fileData); if (uploadResponse.IsSuccess) { fileStream.Seek(0, SeekOrigin.Begin); await _fileProcessor.ProcessStream(fileStream, fileName); } }
public async Task ProcessFile(ElectionResultsFile file) { try { var stream = await DownloadFile(file.URL); var uploadResponse = await UploadFileToStorage(stream, file.Name); if (uploadResponse.IsSuccess) { stream.Seek(0, SeekOrigin.Begin); await _fileProcessor.ProcessStream(stream, file); } } catch (Exception e) { Console.WriteLine(e); } }
private async Task UploadFileToStorage(Stream fileStream, string fileName) { try { var fileData = new FileData { FileName = fileName, Stream = new MemoryStream() }; fileStream.CopyTo(fileData.Stream); var uploadResponse = await _fileRepository.UploadFiles(_config.BucketName, fileData); if (uploadResponse.IsSuccess) { fileStream.Seek(0, SeekOrigin.Begin); await _fileProcessor.ProcessStream(fileStream, fileName); } } catch (Exception e) { _logger.LogError(e, $"Failed to process stream for filename: {fileName}"); throw; } }