mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-01 04:43:13 +00:00
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
|
|
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);
|
||
|
|
}
|
||
|
|
}
|