proposal-system/api/src/ProposalSystem.Infrastructure/Services/S3Service.cs

45 lines
1.2 KiB
C#
Raw Normal View History

using Amazon.S3;
using Amazon.S3.Model;
using ProposalSystem.Application.Interfaces;
namespace ProposalSystem.Infrastructure.Services;
public class S3Service : IS3Service
{
private readonly IAmazonS3 _s3Client;
public S3Service(IAmazonS3 s3Client)
{
_s3Client = s3Client;
}
public Task<string> GeneratePresignedUploadUrlAsync(string bucket, string key, string contentType, int expirationMinutes = 15)
{
var request = new GetPreSignedUrlRequest
{
BucketName = bucket,
Key = key,
Verb = HttpVerb.PUT,
Expires = DateTime.UtcNow.AddMinutes(expirationMinutes),
ContentType = contentType,
};
var url = _s3Client.GetPreSignedURL(request);
return Task.FromResult(url);
}
public Task<string> GeneratePresignedDownloadUrlAsync(string bucket, string key, int expirationMinutes = 60)
{
var request = new GetPreSignedUrlRequest
{
BucketName = bucket,
Key = key,
Verb = HttpVerb.GET,
Expires = DateTime.UtcNow.AddMinutes(expirationMinutes),
};
var url = _s3Client.GetPreSignedURL(request);
return Task.FromResult(url);
}
}