I am trying to convert images to base64, and trying to upload that to AWS S3 using C#. I keep getting a remote server not found exception. But I am able to log in programmatically and list the buckets I have. Can you please identify whats wrong.
static void Main(string[] args)
{
string configaccess = ConfigurationManager.AppSettings["AWSAccesskey"];
string configsecret = ConfigurationManager.AppSettings["AWSSecretkey"];
var s3Client = new AmazonS3Client(
configaccess,
configsecret,
RegionEndpoint.USEast1
);
Byte[] bArray = File.ReadAllBytes("path/foo.jpg");
String base64String = Convert.ToBase64String(bArray);
try
{
byte[] bytes = Convert.FromBase64String(base64String);
using (s3Client)
{
var request = new PutObjectRequest
{
BucketName = "bucketName",
CannedACL = S3CannedACL.PublicRead,
Key = string.Format("bucketName/{0}", "foo.jpg")
};
using (var ms = new MemoryStream(bytes))
{
request.InputStream = ms;
s3Client.PutObject(request);
}
}
}
catch (Exception ex)
{
Console.WriteLine("AWS Fail");
}
}