Elixir aws s3 response - how to get the “key” value?

I using Exaws to get my aws s3 folder directory.
response = ExAws.S3.list_objects(bucket_name, prefix: “img/pic/”,delimiter: “/”) |> ExAws.request(region: “xxxxx”)

I get the response like below. How can i get the “key” value?
Thanks.

{:ok,
 %{
   body: %{
     common_prefixes: [],
     contents: [
       %{
         e_tag: "\"d41d8ez98f00b204s9800998ecg2427e\"",
         key: "img/pic/“,
         last_modified: "2018-11-15T04:15:20.000Z",
         owner: %{
           display_name: “admin”,
           id: "e9d42292cddfe3bf5bab7f1eacfdee6b5d3a64f4528e369c6dc239a13e87c410"
         },
         size: "0",
         storage_class: "STANDARD"
       },
       %{
         e_tag: "\"e2dajb48d4qf7862d257eaf6753b3439\””,
         key: "img/pic/sample.svg",
         last_modified: "2018-11-15T04:15:40.000Z",
         owner: %{
           display_name: “admin”,
           id: "e9d42832cddfe3bf5qob7f1eacfdee6b5d3c64f4528e469c6dc339a13e23c410"
         },
         size: "1149",
         storage_class: "STANDARD"
       }
     ],
     is_truncated: "false",
     marker: "",
     max_keys: "1000",
     name: "s3-test",
     next_marker: "",
     prefix: "img/pic/“
   },
   headers: [
	……..
   ],
   status_code: 200
 }}

Try:

{:ok, response} = ExAws.S3.list_objects(bucket_name, prefix: “img/pic/”,delimiter: “/”) |> ExAws.request(region: “xxxxx”)

Enum.map(response.body.contents, fn( c ) -> c.key end)

It should return a list with the keys.

Best regards

1 Like

It’s working. Thanks for help.:grinning::grinning::grinning:

You can share the code ? I’m trying do the same…