-
Notifications
You must be signed in to change notification settings - Fork 0
/
S3Uploader.cs
41 lines (35 loc) · 1.14 KB
/
S3Uploader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace NotionBackupTool;
using Amazon;
using Amazon.S3;
using Amazon.S3.Transfer;
using System;
using System.Threading.Tasks;
public class S3Uploader
{
private readonly string _bucketName;
private static readonly RegionEndpoint BucketRegion = RegionEndpoint.USWest2; // change this based on your MinIO region
private static IAmazonS3? _s3Client;
public S3Uploader(string s3Host, string s3AccessKey, string s3SecretKey, string s3Bucket)
{
_bucketName = s3Bucket;
_s3Client = new AmazonS3Client(s3AccessKey, s3SecretKey, new AmazonS3Config
{
ServiceURL = s3Host,
ForcePathStyle = true,
SignatureVersion = "s3v4",
});
}
public async Task UploadFileAsync(string filePath)
{
try
{
var fileTransferUtility = new TransferUtility(_s3Client);
// Option 1. Upload a file. The file name is used as the object key name.
await fileTransferUtility.UploadAsync(filePath, _bucketName);
}
catch (Exception e)
{
throw new Exception("Unable to upload file to S3", e);
}
}
}