Skip to content

Instantly share code, notes, and snippets.

@edr3x
Created August 1, 2025 17:18
Show Gist options
  • Select an option

  • Save edr3x/ee965df86c319fe34f1e8a227bb21924 to your computer and use it in GitHub Desktop.

Select an option

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
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