Advertisement
RenSafaray

Untitled

Jun 1st, 2025
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using Amazon.S3;
  2. using Amazon.S3.Model;
  3.  
  4.  
  5. string access_key = "LS49TEFQWUQVYF2AAUFJ";
  6. string secret_key = "YhP77Ys1izvMYSSsbePCBOcxCfoCrq3RHb3mv5m8";
  7. string bucket_name = "bdd82b8c-photo-storage";
  8. string endpoint = "https://s3.twcstorage.ru";
  9.  
  10. var s3Client = new AmazonS3Client(access_key, secret_key, new AmazonS3Config
  11. {
  12.     ServiceURL = endpoint,
  13.     ForcePathStyle = true,
  14. });
  15.  
  16. try
  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. }
  31. catch (AmazonS3Exception ex)
  32. {
  33.     Console.WriteLine(ex.ErrorCode + "\n" + ex.ErrorType);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement