You can upload a file to an AWS S3 bucket and get the URL using the AWS SDK for .NET, which is available as the AWSSDK.S3 NuGet package.
First, install the AWSSDK.S3 package using NuGet. You can do this by running the following command in the Package Manager Console:
Install-Package AWSSDK.S3
using Amazon;
using Amazon.S3;
using Amazon.S3.Transfer;
public class S3FileUploader
{
private const string bucketName = "your-unique-bucket-name";
private const string keyName = "your-unique-object-key";
private const string filePath = "path-to-your-file";
public static string UploadFile()
{
var region = RegionEndpoint.USEast1;
using (var client = new AmazonS3Client(region))
{
var fileTransferUtility = new TransferUtility(client);
fileTransferUtility.Upload(filePath, bucketName, keyName);
fileTransferUtility.Upload(filePath, bucketName, keyName);
var url = $"https://{bucketName}.s3.amazonaws.com/{keyName}";
return url;
}
}
}
Make sure to replace the placeholder values with your actual bucket name, object key, file path, and the appropriate AWS region. This code will upload the file to the specified S3 bucket and provide you with the URL of the uploaded file.