파일에 대한 공개 액세스 제공
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
일반적으로는 웹을 통해 파일 액세스를 공개할 수 있습니다.
이 작업은 PHP 5 표준 환경에서 다음 방법으로 수행할 수 있습니다.
- 스크립트를 사용하여 Google Cloud Storage에 파일 제공: 앱이 파일을 제공합니다.
- 파일을 직접 제공하여 Google Cloud Storage에서 파일을 제공합니다.
app.yaml
에서 정적 핸들러를 사용하여 앱을 통해 업로드된 파일을 제공합니다.
마지막 방법에는 Cloud Storage가 사용되지 않습니다.
스크립트에서 파일 제공
앱에서 파일을 제공하려면 App Engine CloudStorageTools
클래스를 가져옵니다.
이제 CloudStorageTools::serve를 사용해서 Google Cloud Storage에서 파일을 제공합니다.
이 방식으로 앱에서 파일을 제공하면 개발자가 사용자 ID를 확인하고 허가된 사용자만 파일에 액세스하도록 보장할 수 있습니다. 이 방식의 단점은 파일 제공을 위해 애플리케이션이 이 코드를 실행해야 하기 때문에 인스턴스 시간이 소비되고 그로 인한 비용이 발생하는 것입니다.
Google Cloud Storage에서 직접 파일 제공
위 설명처럼 HTTP를 통해 Cloud Storage에서 파일을 직접 제공하면 앱에서 파일을 제공하는 것보다 속도와 경제성이 높아집니다. 파일을 기록할 때는 익명 사용자가 읽을 수 있도록 파일을 구성해야 합니다. 아래 스니펫에서 볼 수 있듯이 acl
스트림 옵션을 public-read
로 설정합니다.
파일이 공개적으로 읽을 수 있도록 Cloud Storage에 작성되면 CloudStorageTools::getPublicUrl을 사용하여 파일의 공개 URL을 구해야 합니다.
다음 예시에서는 일부 난수가 포함된 공개적으로 읽을 수 있는 파일을 만들고 이를 Cloud Storage 버킷에 기록하며 Cloud Storage에서 해당 파일로 리디렉션합니다.
이 방식의 단점은 파일을 누구나 읽을 수 있기 때문에 파일에 액세스할 수 있는 사람을 제어할 수 없다는 점입니다.
앱을 사용하여 업로드된 파일 제공
파일을 읽고 쓰는 다른 방법이 있나요?에서 이 옵션을 자세하게 설명합니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-03-06(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-03-06(UTC)"],[[["This API supports first-generation runtimes and is applicable when upgrading to corresponding second-generation runtimes, while migration to App Engine PHP 7/8 runtime requires consulting the migration guide."],["Files can be made publicly accessible via the web in the PHP 5 standard environment by serving them from a script, serving them directly from Google Cloud Storage, or using the static handler in `app.yaml`."],["Serving files from a script through the App Engine `CloudStorageTools` class allows for user identity verification, but it consumes instance hours, and serving directly from Cloud Storage is faster and more cost-effective, but it lacks user access control."],["To serve files directly from Cloud Storage, files must be configured as readable by anonymous users, utilizing the `public-read` ACL setting and `CloudStorageTools::getPublicUrl` to obtain the public URL."],["Serving files uploaded with your app can be achieved, for more details consult the link provided regarding reading and writing files."]]],[]]