Skip to content

Instantly share code, notes, and snippets.

@shammelburg
Created October 5, 2017 13:01
Show Gist options
  • Save shammelburg/273777ff3643e73f4130eae8f4fd7010 to your computer and use it in GitHub Desktop.
Save shammelburg/273777ff3643e73f4130eae8f4fd7010 to your computer and use it in GitHub Desktop.
IFormFileCollection File Upload AWS
//https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads
[HttpPost]
public void Post(int ItemId)
{
var files = Request.Form.Files;
if (files.Count > 0)
{
using (var client = new AmazonS3Client(_aws.AccessKey, _aws.SecretKey, Amazon.RegionEndpoint.EUWest2))
{
foreach (var file in files)
{
using (var stream = new MemoryStream())
{
file.CopyTo(stream);
var req = new PutObjectRequest()
{
BucketName = $@"{bucket}/test",
Key = file.FileName,
InputStream = stream
};
var response = client.PutObjectAsync(req).Result;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment