· 4 months ago · Jun 01, 2025, 08:50 AM
1using Amazon.S3;
2using Amazon.S3.Model;
3
4
5string access_key = "LS49TEFQWUQVYF2AAUFJ";
6string secret_key = "YhP77Ys1izvMYSSsbePCBOcxCfoCrq3RHb3mv5m8";
7string bucket_name = "bdd82b8c-photo-storage";
8string endpoint = "https://s3.twcstorage.ru";
9
10var s3Client = new AmazonS3Client(access_key, secret_key, new AmazonS3Config
11{
12 ServiceURL = endpoint,
13 ForcePathStyle = true,
14});
15
16try
17{
18 using (var fileStream = new FileStream("C:/Users/ilyae/Documents/1f64f.png", FileMode.Open))
19 {
20 var request = new PutObjectRequest
21 {
22 BucketName = bucket_name,
23 Key = "1f64f.png",
24 InputStream = fileStream
25 };
26
27 await s3Client.PutObjectAsync(request);
28 Console.WriteLine("Файл успешно загружен!");
29 }
30}
31catch (AmazonS3Exception ex)
32{
33 Console.WriteLine(ex.ErrorCode + "\n" + ex.ErrorType);
34}