c# .netcore Get ImageURL of all files under amazon s3 folder

string imageUrl = $"{_appSettings.AWSS3BucketUrl}{imagePath}{result}";

You’re telling C# to concatenate a string with “result”, but “result” is not a string, it’s an array. To tell the compiler what you really want, you need to get the individual strings out of the array and use those instead.

It also looks like you’re converting your result into JSON in code we can’t see. If that’s the case, you could try returning a list of objects from your function instead of a string, which will then get serialized into something a lot closer to your expected output:

// make a simple class that will be serialized cleanly
public class MenuURL
    public string menuUrl;

// .... back in your function ....

List<MenuURL> URLs = new List<MenuURL>();

// Loop through your "results" variable
foreach (string str in result)
    MenuURL url = new MenuURL()
        menuUrl = $"{_appSettings.AWSS3BucketUrl}{imagePath}{str}"


return URLs;

When you convert the list you get back into JSON, it should look more like what you want, ie:

          "menuUrl" : "https://...bucketpath../test.jpg"
          "menuUrl": "https://...bucketpath../test2.jpg"

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top