Skip to content

Commit

Permalink
feat(bl): copy one bucket to another and create shareable url of the …
Browse files Browse the repository at this point in the history
…object (#183)

Co-authored-by: jaybeeelsdon <justin@chi.swan.ac.uk>
  • Loading branch information
mahadi99xy and jaybeeelsdon authored Oct 6, 2023
1 parent 41f8cf0 commit c315136
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/BL/Services/IMinioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface IMinioHelper
Task<bool> FetchAndStoreObject(string url, MinioSettings minioSettings, string bucketName, string key);
Task<bool> RabbitExternalObject(FetchFileMQ msgBytes);
Task<bool> CreateBucketPolicy(string bucketName);
Task<bool> CopyObject(MinioSettings minioSettings, string sourceBucketName, string destinationBucketName, string sourceObjectKey, string destinationObjectKey);
Task<string> ShareMinioObject(MinioSettings minioSettings, string bucketName, string objectKey);

}
}
34 changes: 34 additions & 0 deletions src/BL/Services/MinioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,40 @@ public async Task<bool> CreateBucketPolicy(string bucketName)
return true;
}

public async Task<bool> CopyObject(MinioSettings minioSettings, string sourceBucketName, string destinationBucketName, string sourceObjectKey, string destinationObjectKey)
{
var amazonS3Client = GenerateAmazonS3Client(minioSettings);

var request = new CopyObjectRequest
{
SourceBucket = sourceBucketName,
DestinationBucket = destinationBucketName,
SourceKey = sourceObjectKey,
DestinationKey = destinationObjectKey
};

var result = await amazonS3Client.CopyObjectAsync(request);

return true;
}

public async Task<string> ShareMinioObject(MinioSettings minioSettings, string bucketName, string objectKey)
{
var amazonS3Client = GenerateAmazonS3Client(minioSettings);

var expiration = DateTime.Now.AddHours(1);


var url = amazonS3Client.GetPreSignedURL(new GetPreSignedUrlRequest
{
BucketName = bucketName,
Key = objectKey,
Expires = expiration,
});

return url;
}

#region PrivateHelpers
private AmazonS3Config GenerateAmazonS3Config(MinioSettings minioSettings)
{
Expand Down

0 comments on commit c315136

Please sign in to comment.