HI Guys,
How to Upload file in aws s3 bucket using I am User Role in C# code?
Thanks & Regards,
Saravanakumar
HI Guys,
How to Upload file in aws s3 bucket using I am User Role in C# code?
Thanks & Regards,
Saravanakumar
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 28, 2023, 11:01 AM EST
Hello Saravanakumar,
Please refer below link it has given fully working demo program.
https://stackoverflow.com/a/25814973/3054222
Thanks
Naimish Makwana
Amit MohantyRank #112 · 20K reputationPosted Feb 28, 2023, 11:37 PM EST
Try this
var credentials = new Amazon.Runtime.BasicAWSCredentials("accessKey", "secretKey"); var config = new AmazonS3Config { RegionEndpoint = RegionEndpoint.USEast1, // replace with your region ForcePathStyle = true // required for non-AWS endpoints }; var s3Client = new AmazonS3Client(credentials, config); var putRequest = new PutObjectRequest { BucketName = "my-bucket", Key = "my-file.txt", FilePath = "path/to/my-file.txt" }; var response = s3Client.PutObjectAsync(putRequest).Result;This will upload the file "my-file.txt" from your local file system to the S3 bucket "my-bucket" using the key "my-file.txt".
horald Henry18 reputationPosted Mar 1, 2023, 8:10 AM EST
using Amazon.S3; using Amazon.S3.Transfer; string accessKey = "YOUR_ACCESS_KEY"; string secretKey = "YOUR_SECRET_KEY"; string bucketName = "YOUR_BUCKET_NAME"; string filePath = "LOCAL_FILE_PATH"; string keyName = "S3_OBJECT_KEY_NAME"; var credentials = new Amazon.Runtime.BasicAWSCredentials(accessKey, secretKey); var client = new AmazonS3Client(credentials, Amazon.RegionEndpoint.YOUR_REGION); var transferUtility = new TransferUtility(client); await transferUtility.UploadAsync(filePath, bucketName, keyName);This could work but make sure that the IAM user role has the necessary permissions to upload files to the S3 bucket. Specifically, the user role should have the
s3:PutObjectpermission for the target bucket.