Home > OS >  Retrieving files from s3 with content-type
Retrieving files from s3 with content-type

Time:07-23

Is there any proper way to retrieve files from s3 with the Content-type using python or AWS CLI?

I've searched and made some queries as below but the first one seems not as intended.

aws s3 ls --summarize --human-readable --recursive s3://<Bucket Name> | egrep '*.jpg*'

And the following query seems working but it also returns 404 errors.

for KEY in $(aws s3api list-objects --bucket <Bucket Name> --query "Contents[].[Key]" --output text) do aws s3api head-object --bucket <Bucket Name> --key $KEY --query "[\`$KEY\`,ContentType]" --output text | awk '$2 == "image/jpeg" { print $1 }'done

CodePudding user response:

One of the reason is, the variable is not expending in the query parameters

--query "[\`$KEY\`,ContentType]"

Here you can look for more details.

enter image description here

  • Related