Sample scripts and AWS infrastructure to test the AWS S3 UTF-8 content disposition examples outlined in my blog post: AWS S3 UTF-8 Content Disposition.
Install required dependencies:
- bash (command-not-found)
- terraform v1.1.5 (tfenv can be useful)
- ruby v3.1.0
Create an AWS IAM user with the relevant permissions for the Terraform setup (S3, DynamoDB, CloudFront, etc) or use AdministratorAccess
for quicker setup.
Add the access keys for the IAM user to the aws-s3-utf-8-content-disposition
AWS profile in the credentials list on your machine:
sudo vim ~/.aws/credentials
[aws-s3-utf-8-content-disposition]
aws_access_key_id = <iam user access key id>
aws_secret_access_key = <iam user secret key>
Fork or clone the project and navigate to the project root directory.
IMPORTANT: While the infrastructure required for this example project is covered by the AWS Always free
tier, high usage or installation on an account with other resource usage may cost you money. Please remember to evaluate costs and teardown project afterwards.
Run build script:
./tools/build_infrastructure
Run destroy script:
./tools/destroy_infrastructure
Once the project infrastructure is built, the examples script can be run.
Each example creates a signed CloudFront URL which can be used to download the sample S3 object not-a-cat.jpg
with a different filename. The filename is set using the response-content-disposition
parameter and the URL will be valid for 600 seconds by default.
The examples script is written in Ruby and is run by calling the follow command, replacing <example-number>
with the number of the example you want to run:
ruby ./examples.rb <example-number>
Copy and paste the outputted URL into your browser to download the file and test the filename.
Examples:
- 1: Sets Content-Disposition on request to download object with the filename
jessie.jpg
- 2: Sets filename to
"고양이.jpg"
, URL encoding the filename in theresponse-content-disposition
parameter once. Results in AWS S3 error. - 3: Sets filename to
"고양이.jpg"
, URL encoding the UTF-8 filename in theresponse-content-disposition
parameter twice, allowing AWS S3 to return it to the client in ISO-8859-1