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 <CreateS3BucketResponse> > CreateS3Bucket([FromRoute] string bucketName) { var bucketExist = await _repository.DoesS3BucketExists(bucketName); if (bucketExist) { return(BadRequest("S3 bucket already exists")); } var result = await _repository.CreateBucket(bucketName); return(Ok(result)); }
public async Task <ActionResult> CreateBucket([FromBody] BucketInfo bucketInfo) { var createResponse = await _bucketRepository.CreateBucket(bucketInfo.Name); if (createResponse.IsSuccess) { return(Ok(createResponse.Value)); } else { return(BadRequest(createResponse.Error)); } }
public async Task <ActionResult <CreateBucketResponse> > CreateS3Bucket([FromRoute] string bucketName) { var bucketExists = await _bucketRepository.DoesS3BucketExist(bucketName); if (bucketExists) { return(BadRequest("Bucket Already Exists")); } var result = await _bucketRepository.CreateBucket(bucketName); if (result == null) { return(BadRequest()); } return(Ok(result)); }
public async Task <ActionResult <CreateBucketResponse> > CreateS3Bucket([FromRoute] string bucketName) { bool bucketExists = await _bucketRepo.DoesS3BucketExists(bucketName); if (bucketExists) { return(BadRequest("S3 bucket already exists.")); } var result = _bucketRepo.CreateBucket(bucketName); if (result == null) { return(BadRequest()); } else { return(Ok(result)); } }
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}"); } }