Skip to content

Instantly share code, notes, and snippets.

@evadne
Created February 2, 2018 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evadne/41c04d927b25ce1cf68e2f1fb851d349 to your computer and use it in GitHub Desktop.
Save evadne/41c04d927b25ce1cf68e2f1fb851d349 to your computer and use it in GitHub Desktop.
defp prepare_signed_url({region, bucket, object}, friendly_name) do
config = ExAws.Config.new(:s3, %{region: region})
encoded_name = URI.encode(friendly_name, fn
x when ?0 <= x <= ?9 -> true
x when ?A <= x <= ?Z -> true
x when ?a <= x <= ?z -> true
_ -> false
end)
options = [
expires_in: 1800,
query_params: [{
"response-content-disposition",
"attachment; filename*=UTF-8''#{encoded_name}"
}]
]
ExAws.S3.presigned_url(config, :get, bucket, object, options)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment