问题
I want to output every image inside the s3 bucket folder Business_Menu. Only way
public async Task<(string url, Image image)> GetAWSPreSignedS3Url(entities.Cafe cafe, string mimeType, Constants.ImageType type)
{
AmazonS3Client s3Client = new AmazonS3Client(_appSettings.AWSPublicKey, _appSettings.AWSPrivateKey, Amazon.RegionEndpoint.APSoutheast2);
string imagePath;
string cafeName = trimSpecialCharacters(cafe.Name);
var cafeId = cafe.CafeId;
Image image;
switch (type)
{
case Constants.ImageType.Logo:
imagePath = $"Company_logo/{cafeName}.{mimeType}";
image = await updateImageAsync($"{_appSettings.AWSS3BucketUrl}{imagePath}", Constants.ImageType.Logo, cafe);
break;
case Constants.ImageType.Menu:
imagePath = $"Business_menu/{cafeId}/{restaurantName}.{mimeType}";
image = await updateImageAsync($"{_appSettings.AWSS3BucketUrl}{imagePath}", Constants.ImageType.Menu, cafe);
break;
default:
imagePath = $"images/{Guid.NewGuid()}.{mimeType}";
image = await updateImageAsync($"{_appSettings.AWSS3BucketUrl}{imagePath}", Constants.ImageType.Story, cafe);
break;
}
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest
{
BucketName = _appSettings.AWSS3BucketName,
Key = imagePath,
Expires = DateTime.Now.AddHours(1),
ContentType = $"image/{mimeType}",
Verb = HttpVerb.PUT
};
var result = (s3Client.GetPreSignedURL(request), image);
return result;
}
This outputs the image urls. Was thinking to add the looping here and keep looking through the bucket and get all the images and store it in an array. Is their another way to query the s3 bucket and get all the images in a array?
public async Task<MenuResponse> GetMenuUrl(int cafeId, string mimeType)
{
var cafe = await _context.Cafe.Where(w => w.CafeId == cafeId).FirstOrDefaultAsync();
var result = await _storyService.GetAWSPreSignedS3Url(cafe, mimeType, Constants.ImageType.Menu); //get menu url
var response = new MenuResponse()
{
MenuUrl = result.url
};
return response;
}
来源:https://stackoverflow.com/questions/64565689/how-to-retrieve-multiple-images-from-amazon-s3-using-one-imagepath-at-once