Created
August 1, 2025 17:18
-
-
Save edr3x/ee965df86c319fe34f1e8a227bb21924 to your computer and use it in GitHub Desktop.
AWS Cloudfront Function to override Content Disposition for view only and download the file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function handler(event) { | |
| var response = event.response; | |
| var uri = event.request.uri; | |
| var query = event.request.querystring; | |
| var filename = uri.split("/").pop(); | |
| // Override filename if query param is provided | |
| if (query.filename && query.filename.value) { | |
| filename = query.filename.value; | |
| } | |
| if (query.download && query.download.value === "true") { | |
| response.headers['content-disposition'] = { | |
| value: 'attachment; filename="' + filename + '"' | |
| }; | |
| } else if (query.inline && query.inline.value === "true") { | |
| response.headers['content-disposition'] = { | |
| value: 'inline; filename="' + filename + '"' | |
| }; | |
| } | |
| return response; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment