Articles → AWS SDK AND CSHARP → Upload File(S) And Folder(S) On S3 Bucket Using C# Code
Upload File(S) And Folder(S) On S3 Bucket Using C# Code
Steps
- Create s3 bucket.
- Create a console application and write code.
- Output.
Create S3 Bucket
Click to Enlarge
Create A Console Application And Write Code
using Amazon;
using Amazon.Runtime;
using Amazon.S3;
using Amazon.S3.Transfer;
using System.IO;
namespace dotnetS3
{
class Program
{
public static void Main(string[] args)
{
string bucketName = "gyansangrah-bucket";
UploadFilesAndFolder(bucketName);
}
static void UploadFilesAndFolder(string bucketName)
{
var region = RegionEndpoint.GetBySystemName("us-east-2");
AWSCredentials credentails = new BasicAWSCredentials("<Access Id>", "<Secret Key>");
AmazonS3Client client = new AmazonS3Client(credentails);
TransferUtility utility = new TransferUtility(client);
TransferUtilityUploadDirectoryRequest transferUtilityUploadDirectoryRequest
= new TransferUtilityUploadDirectoryRequest()
{
BucketName = bucketName,
Directory = @"C:\temp\cluster",
SearchOption = SearchOption.AllDirectories
};
utility.UploadDirectory(transferUtilityUploadDirectoryRequest);
}
}
}
Click to Enlarge
Output
Click to Enlarge