ASP.NET MVC - Uploading an image to Amazon S3

Matthew H picture Matthew H · Sep 23, 2010 · Viewed 12.3k times · Source

I have my image from Request.Files[0]. Now, how do I upload this image to S3? I see that in the AWS .NET API you have to specify ContentBody when putting an object which is a string. How would I get the content body of my file?

Answer

Matthew H picture Matthew H · Sep 23, 2010
var file = Request.Files[0];
PutObjectRequest request = new PutObjectRequest();
request.BucketName = "mybucket"
request.ContentType = contentType;
request.Key = key;
request.InputStream = file.InputStream;
s3Client.PutObject(request);