-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS3Uploader.cs
More file actions
43 lines (36 loc) · 1.18 KB
/
S3Uploader.cs
File metadata and controls
43 lines (36 loc) · 1.18 KB
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
42
43
namespace HackMdBackup;
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,
});
}
public async Task UploadFileAsync(string filePath)
{
try
{
var fileTransferUtility = new TransferUtility(_s3Client, new TransferUtilityConfig
{
MinSizeBeforePartUpload = 6L * 1024 * 1024 * 1024 // 6GB - effectively disable multipart upload
});
await fileTransferUtility.UploadAsync(filePath, _bucketName);
}
catch (Exception e)
{
throw new Exception("Unable to upload file to S3", e);
}
}
}