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 <ActionResult <CreateBucketResponse> > createS3Bucket([FromRoute] string bucketname) { var bucketExists = await _bucketRepository.DoesS3BucketExist(bucketname); if (bucketExists) { return(BadRequest("S3 bucket already exists")); } var result = await _bucketRepository.PutBucket(bucketname); if (result == null) { return(BadRequest()); } return(Ok(result)); }
public async Task <ActionResult <CreateBucketResponse> > CreateBucketAsync(string bucketName) { _logger.LogInformation("Incoming Create Bucket request"); if (await _bucketRepository.DoesS3BucketExist(bucketName)) { return(BadRequest("Bucket already exists!")); } var result = await _bucketRepository.CreateS3BucketAsync(bucketName); if (result != null && !string.IsNullOrEmpty(result.RequestId)) { return(Ok(result)); } _logger.LogInformation("Something went wrong along the way"); return(BadRequest("Unable to create S3 bucket")); }
public async Task <ActionResult <CreateBucketResponse> > CreateS3Bucket([FromRoute] string bucketName) { // validation to check if the bucket already exists var bucketExists = await _bucketRepository.DoesS3BucketExist(bucketName); if (bucketExists) { return(BadRequest("S3 bucket already exists")); } // logic to create S3 bucket. var result = await _bucketRepository.CreateBucket(bucketName); if (result == null) { return(BadRequest()); } return(Ok(result)); }
private async Task InitializeBucket() { try { var bucketName = _config.BucketName; Log.LogInformation($"Initializing bucket {bucketName}"); var bucketExists = await _bucketRepository.DoesS3BucketExist(bucketName); if (bucketExists == false) { Log.LogInformation($"Bucket {bucketName} doesn't exist"); var response = await _bucketRepository.CreateBucket(bucketName); if (response.IsFailure) { Log.LogWarning($"Failed to create bucket: {response.Error}"); } } } catch (Exception e) { Log.LogError(e, $"Failed to create bucket {_config.BucketName}"); } }