Created
October 5, 2017 13:01
-
-
Save shammelburg/273777ff3643e73f4130eae8f4fd7010 to your computer and use it in GitHub Desktop.
IFormFileCollection File Upload AWS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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