How to retrieve multiple images from Amazon s3 using one imagePath at once?

谁说胖子不能爱 提交于 2021-02-11 12:45:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!