Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Created October 9, 2012 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradoyler/3860477 to your computer and use it in GitHub Desktop.
Save bradoyler/3860477 to your computer and use it in GitHub Desktop.
Upload a file to S3 (asp.net)
HttpPostedFileBase file = Request.Files[0];
if (file.ContentLength > 0) // accept the file
{
string accessKey = "XXXXXXXXXXX";
string secretKey = "122334XXXXXXXXXX";
AmazonS3 client;
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey))
{
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName("yourbucket")
.WithCannedACL(S3CannedACL.PublicRead)
.WithKey("meals/test.jpg").InputStream = file.InputStream;
S3Response response = client.PutObject(request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment