클라우드프론트에서 파일명 변경하여 다운로드 받는 방법
제목대로 입니다.
일반적으로 PHP에서 다운로드 받을때 파일명을 변경해주는 방법은 HTTP 헤더에 추가만 해주는 방식으로 간단한데요. 클라우드 프론트를 이용할때는 아래 순서를 거쳐야 합니다. 그리고 S3에서 받는 방법에 대한 예제 이기 때문에 S3에서 변경해주는 방법을 알면 더 도움이 됩니다.
이것만 알아보고 S3부분을 알아보지 않아서 시간이 더 소요되었지요.
response-content-disposition-cloudfront.txt
1) Log in to aws console.
2) Click cloudfront
3) Click behaviors
4) Select pattern and edit
5) Set Forward Query Strings - Yes
6) click "Yes, edit" to save your edits
7) It may take some time for cloudfront cache to expire, so that these changes take effect
8) Your code should do something like below.
Add the escaped string as a query string to the url before signing it.
from boto.cloudfront.distribution import Distribution
d = Distribution()
encoded_headers = 'response-content-disposition=attachment%3B%20filename%3Dname_of_file_here.txt'
url = d.create_signed_url('%s%s?%s' % (hostname, filepath, encoded_headers),
key_id,
private_key_string=private_key_string,
expire_time=ttl)
설정하는 방법입니다
처음엔 람다로 테스트를 했는데요. 그것이 아니라 이 방법을 이용해야 합니다. 람다 테스트는 되는에 올리면 다른 증상이 나와서 고생했는데 이 부분에 대한 정보가 많지 않아 도움이 될듯 합니다.
그리고 이것은 우리가 흔히 페이지 변경되었을때 뒤쪽에 파라미터값을 변경하는 방법을 많이 사용하는데 전달에 대한 설정을 안하고 사용하면 그 방법은 잘못된 방법입니다.(클라우드 프론트 사용할때)
---------------------------------------------------------------
기본적은 사용방법은 아래 페이지에 잘 나와 있다.
https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started_basic-usage.html
서명4 관련된것.
# AWS설명서
PHP API 메뉴얼
https://docs.aws.amazon.com/aws-sdk-php/v3/api/index.html#m=AmazonS3/get_object_url
클프 서명된 URL
https://docs.aws.amazon.com/ko_kr/AmazonCloudFront/latest/DeveloperGuide/CreateURL_PHP.html