Hi,
The code below will successfully save in S3 bucket but how can I specify to save under a specific folder?
public async Task<IActionResult> UploadFileToS3(IFormFile file)
{
var credentials = new BasicAWSCredentials("access key id", "secret access key");
using (var amazonS3Client = new AmazonS3Client(credentials, RegionEndpoint.APSouth1))
{
using (var memorystream = new MemoryStream())
{
file.CopyTo(memorystream);
var request = new TransferUtilityUploadRequest
{
InputStream = memorystream,
Key = file.FileName,
BucketName = "myaspstorage",
ContentType = file.ContentType,
};
var transferUtility = new TransferUtility(amazonS3Client);
await transferUtility.UploadAsync(request);
}
}
S3FileDetails fileDetails = new S3FileDetails();
fileDetails.FileName = file.FileName;
fileDetails.Filedate = DateTime.Today;
_db.S3FileDetails.Add(fileDetails);
_db.SaveChanges();
ViewBag.Success = "File uploaded to S3 Bucket successfully!";
return RedirectToAction(nameof(Index));
}