Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC - Uploading an image to Amazon S3

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?

like image 286
Matthew H Avatar asked Sep 23 '10 18:09

Matthew H


People also ask

How do I upload images to Amazon S3?

To upload folders and files to an S3 bucketSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to upload your folders or files to. Choose Upload.

Can I store images in S3 bucket?

You can create a dataset using images stored in an Amazon S3 bucket. With this option, you can use the folder structure in your Amazon S3 bucket to automatically classify your images. You can store the images in the console bucket or another Amazon S3 bucket in your account.


1 Answers

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);
like image 100
Matthew H Avatar answered Oct 08 '22 00:10

Matthew H