Go 1.11 已終止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 Go 1.11 應用程式,即使貴機構先前使用機構政策重新啟用舊版執行階段的部署作業也一樣。現有的 Go 1.11 應用程式在
淘汰日期過後,仍會繼續執行並接收流量。建議您
遷移至最新支援的 Go 版本。
使用 Cloud Storage
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如果 Go 1.11 應用程式需要在執行階段期間讀取及寫入檔案,或是提供如影片、圖片或其他靜態內容等檔案,建議您使用 Cloud Storage 值區。
建立應用程式時,App Engine 會建立預設值區。這個值區提供的前 5 GB 儲存空間免費,並包含 Cloud Storage I/O 作業的免費配額。您可以建立其他 Cloud Storage 值區,但只有預設值區免費提供前 5 GB 的儲存空間。
將 Cloud Storage 與 App Engine 搭配使用
如要透過 App Engine 應用程式使用 Cloud Storage 值區:
在 App Engine 專案中查看現有值區的名稱。從 Cloud Storage 上傳或下載資料時,要指定這些名稱。
建議您將 Cloud Storage 值區的名稱儲存在應用程式的環境變數中,而不是以硬式編碼的方式將這些名稱寫入應用程式的程式碼中。
在您的應用程式中使用 go get cloud.google.com/go/storage
指令宣告 Cloud Storage 為依附元件。您也可以選擇在應用程式的 go.mod
檔案中宣告依附元件。進一步瞭解如何指定依附元件。
使用 Google Cloud 用戶端程式庫,從您的值區上傳或下載資料。
如要瞭解如何提供靜態內容,請參閱「儲存和提供靜態檔案」一文。
使用預設值區
建立應用程式時,App Engine 會建立預設值區。這個值區提供的前 5 GB 儲存空間免費。預設值區也包含免費的 Cloud Storage I/O 作業配額。詳情請參閱定價、配額與限制一節。超過 5GB 限制的部分將須付費。
預設值區的名稱格式如下:
project-id.appspot.com
App Engine 也會在部署應用程序的新版本時,建立做為暫存空間的值區。這個值區名為 staging.project-id.appspot.com
,僅供 App Engine 使用。應用程式無法與此值區互動。
設定值區與物件權限
與應用程式相關聯的服務帳戶需要具備讀取及寫入專案中值區的權限。如要瞭解所需權限,請參閱「Cloud Storage 的 IAM 角色」。
通常,與應用程式相關聯的服務帳戶是 預設 App Engine 服務帳戶。
根據貴機構的政策設定,系統可能會自動為預設服務帳戶授予專案的編輯者角色。強烈建議您
套用 iam.automaticIamGrantsForDefaultServiceAccounts
機構政策限制,停用自動角色授予功能。如果您是在 2024 年 5 月 3 日之後建立機構,系統預設會強制執行這項限制。
如果您停用自動角色授予功能,就必須決定要將哪些角色授予預設服務帳戶,然後自行授予這些角色。
如果預設服務帳戶已具有「編輯者」角色,建議您將「編輯者」角色替換為權限較低的角色。如要安全地修改服務帳戶的角色,請使用政策模擬器查看變更的影響,然後授予及撤銷適當的角色。
如要進一步瞭解如何允許其他使用者、應用程式或專案存取值區及其內容,請參閱「設定值區權限」和「設定物件權限」的相關說明。
搭配本機開發伺服器使用 Cloud Storage
App Engine 本機開發伺服器不會模擬 Cloud Storage,因此所有 Cloud Storage 要求都必須透過網際網路傳送至實際的 Cloud Storage 值區。
定價、配額與限制
Cloud Storage 用戶端程式庫對於 Cloud Storage 的呼叫沒有相關的頻寬費用,但會產生作業費用。此外,呼叫會計入您的網址擷取配額用量,因為程式庫會使用網址擷取服務與 Cloud Storage 互動。
請注意,Cloud Storage 屬付費使用服務;系統會根據 Cloud Storage 價目表向您收費。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-04 (世界標準時間)。
[[["容易理解","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-09-04 (世界標準時間)。"],[[["\u003cp\u003eApp Engine recommends using a Cloud Storage bucket for reading, writing, and serving files during runtime in Go 1.11 apps.\u003c/p\u003e\n"],["\u003cp\u003eWhen you create an app, App Engine provides a default bucket with the first 5GB of storage and a free quota for Cloud Storage I/O operations.\u003c/p\u003e\n"],["\u003cp\u003eTo interact with Cloud Storage from your app, you should specify bucket names using environment variables and declare Cloud Storage as a dependency using the \u003ccode\u003ego get\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine automatically creates a temporary staging bucket for deploying new versions, but it's not accessible to apps.\u003c/p\u003e\n"],["\u003cp\u003eThe service account linked to your app needs the appropriate permissions to interact with buckets, and you should consider replacing the Editor role with more restrictive roles for enhanced security.\u003c/p\u003e\n"]]],[],null,["# Using Cloud Storage\n\nIf your Go 1.11 app needs to read and write files during runtime,\nor serve files such as movies, images or other static content, we recommend you\nuse a [Cloud Storage](/storage/docs) bucket.\n\nApp Engine creates a [default bucket](#default_bucket) when you create\nan app. This bucket provides the first 5GB of storage for free and includes a\nfree quota for Cloud Storage I/O operations. You can\n[create other Cloud Storage buckets](/storage/docs/creating-buckets),\nbut only the default bucket includes the first 5GB of storage for free.\n\nUsing Cloud Storage with App Engine\n-----------------------------------\n\nTo use a Cloud Storage bucket from an App Engine app:\n\n1. [View the names of the existing buckets](/storage/docs/listing-buckets)\n in your App Engine project. You'll specify these names when you\n upload or download data from Cloud Storage.\n\n We recommend that you store the names of your Cloud Storage buckets\n in your app's [environment variables](/appengine/docs/standard/reference/app-yaml#environment_variables)\n instead of hard coding them into your app.\n2. In your app, declare Cloud Storage as a dependency\n\n by using the `go get cloud.google.com/go/storage` command. Alternatively,\n you can declare dependencies in your app's `go.mod` file. Learn more\n [about specifying dependencies](/appengine/docs/legacy/standard/go111/specifying-dependencies).\n\n \u003cbr /\u003e\n\n3.\n Use the Google Cloud Client Library to\n [upload](/storage/docs/uploading-objects)\n or [download](/storage/docs/downloading-objects)\n data from your buckets.\n\n\n For information about serving static content, see [Storing and Serving\n Static Files](/appengine/docs/legacy/standard/go111/serving-static-files).\n\n### Using the default bucket\n\nWhen you create an app, App Engine creates a default bucket that\nprovides the first 5GB of storage for free. The default bucket also includes\na free quota for Cloud Storage I/O operations. See\n[Pricing, quotas, and limits](#pricing_quotas_and_limits) for details. You will\nbe charged for storage over the 5GB limit.\n\nThe name of the default bucket is in the following format: \n\n```\nproject-id.appspot.com\n```\n\n\u003cbr /\u003e\n\nApp Engine also creates a bucket that it uses for temporary\nstorage when it deploys new versions of your app. This bucket, named\n`staging.`\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e`.appspot.com`, is for use by\nApp Engine only. Apps can't interact with this bucket.\n\n### Setting bucket and object permissions\n\nThe service account that's associated with your app needs permissions to read\nand write to buckets in your project. To learn which permissions are required,\nsee [IAM roles for\nCloud Storage](/storage/docs/access-control/iam-roles).\n\nTypically, the\nservice account that's associated with your app is the [default\nApp Engine service\naccount](/appengine/docs/legacy/standard/go111/service-account).\n\n\nDepending on your organization policy configuration, the default service account might\nautomatically be granted the [Editor role](/iam/docs/roles-overview#basic) on your\nproject. We strongly recommend that you disable the automatic role grant by [enforcing the `iam.automaticIamGrantsForDefaultServiceAccounts` organization policy\nconstraint](/resource-manager/docs/organization-policy/restricting-service-accounts#disable_service_account_default_grants). If you created your organization after May 3, 2024, this\nconstraint is enforced by default.\n\n\nIf you disable the automatic role grant, you must decide which roles to grant to the default\nservice accounts, and then [grant these\nroles](/iam/docs/granting-changing-revoking-access) yourself.\n\n\nIf the default service account already has the Editor role, we recommend that you replace the\nEditor role with less permissive roles.To safely modify the service account's roles, use [Policy Simulator](/policy-intelligence/docs/simulate-iam-policies) to see the impact of\nthe change, and then [grant and revoke the\nappropriate roles](/iam/docs/granting-changing-revoking-access).\n\n\u003cbr /\u003e\n\nFor information about allowing other users, apps, or projects to access a bucket\nand its contents, see\n[Setting bucket permissions](/storage/docs/cloud-console#_bucketpermission)\nand\n[Setting object permissions](/storage/docs/cloud-console#_permissions).\n\nUsing Cloud Storage with the local development server\n-----------------------------------------------------\n\nThe App Engine local development server doesn't emulate Cloud Storage,\nso all Cloud Storage requests must be sent over the Internet to an\nactual Cloud Storage bucket.\n\nPricing, quotas, and limits\n---------------------------\n\nThere are no bandwidth charges associated with Cloud Storage client library\ncalls to Cloud Storage. However, there are\n[operations charges](/storage/pricing#operations-pricing).\nIn addition, the calls count against your\n[URL fetch quota](/appengine/docs/quotas#UrlFetch)\nas the library uses the URL Fetch service to interact with Cloud Storage.\n\nNotice that Cloud Storage is a pay-to-use service;\nyou will be charged according to the Cloud Storage\n[price sheet](/storage/pricing)."]]