使用 Cloud Storage for Firebase,您可以上传和共享用户生成的内容(如图片和视频),以便将富媒体内容融入您的应用。您的数据存储在 Google Cloud Storage 存储桶中,这是一个 EB 级对象存储解决方案,具备高可用性和全局冗余性。通过 Cloud Storage for Firebase,您可以直接从移动设备和网络浏览器安全上传这些文件,从容应对网络不够稳定的情况。
finalstorage=FirebaseStorage.instance;// Alternatively, explicitly specify the bucket name URL.// final storage = FirebaseStorage.instanceFor(bucket: "gs://<var>BUCKET_NAME</var>");
[null,null,["最后更新时间 (UTC):2025-08-13。"],[],[],null,["\u003cbr /\u003e\n\nCloud Storage for Firebase lets you upload and share user generated content, such\nas images and video, which allows you to build rich media content into your\napps. Your data is stored in a\n[Google Cloud Storage](//cloud.google.com/storage) bucket --- an\nexabyte scale object storage solution with high availability and global\nredundancy. Cloud Storage for Firebase lets you securely upload these files\ndirectly from mobile devices and web browsers, handling spotty networks with\nease.\n\nBefore you begin\n\n1. If you haven't already, make sure you've completed the\n [getting started guide for Flutter apps](/docs/flutter/setup).\n This includes:\n\n - Creating a Firebase project.\n\n - Installing and initializing the Firebase SDKs for Flutter.\n\n2. Make sure your Firebase project is on the [pay-as-you-go Blaze pricing plan](/pricing). If\n you're new to Firebase and Google Cloud, check if you're eligible for a\n [$300 credit](/support/faq#pricing-free-trial).\n\n| **Important** : The following changes to pricing plan requirements are happening for Cloud Storage for Firebase. Learn more in the [FAQs](/docs/storage/faqs-storage-changes-announced-sept-2024).\n|\n| - **Starting\n| October 30, 2024** , your Firebase project must be on the [pay-as-you-go Blaze pricing plan](/pricing) to provision a new Cloud Storage for Firebase default bucket. The bucket can optionally use the [\"Always Free\" tier](https://cloud.google.com/storage/pricing#cloud-storage-always-free) for Google Cloud Storage.\n| - **Starting\n| October 1, 2025** , your Firebase project must be on the [pay-as-you-go Blaze pricing plan](/pricing) to maintain access to your default bucket and all other Cloud Storage resources. Any `*.appspot.com` default bucket will maintain its current no-cost level of usage even on the Blaze pricing plan.\n\nCreate a default Cloud Storage bucket\n\n1. From the navigation pane of the [Firebase console](//console.firebase.google.com/), select **Storage**.\n\n If your project is not yet on the pay-as-you-go Blaze pricing plan, then you'll be\n prompted to upgrade your project.\n2. Click **Get started**.\n\n3. Select a [location](/docs/storage/locations) for your default bucket.\n\n - Buckets in `US-CENTRAL1`, `US-EAST1`, and `US-WEST1` can take advantage of the\n [\"Always Free\" tier](https://cloud.google.com/storage/pricing#cloud-storage-always-free) for Google Cloud Storage.\n Buckets in all other locations follow\n [Google Cloud Storage pricing and usage](https://cloud.google.com/storage/pricing).\n\n - If you'd like, you can later\n [create multiple buckets](#use_multiple_storage_buckets), each with its\n own location.\n\n4. Configure the Firebase Security Rules for your default bucket. During development,\n consider [setting up your rules for public access](#set_up_public_access).\n\n5. Click **Done**.\n\nYou can now view the bucket in the\n[Cloud Storage *Files* tab](https://console.firebase.google.com/project/_/storage/)\nof the Firebase console. Your default bucket name format is\n\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.firebasestorage.app`.\n| **Note:** Starting October 30, 2024, all new default Cloud Storage buckets have the name format \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.firebasestorage.app`. Any default buckets created *before* that date have the name format \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.appspot.com`. Learn more in the [FAQs](/docs/storage/faqs-storage-changes-announced-sept-2024#all-changes-default-storage-bucket).\n\nSet up public access\n\nCloud Storage for Firebase provides a declarative rules language that lets you\ndefine how your data should be structured, how it should be indexed, and when\nyour data can be read from and written to. By default, read and write access to\nCloud Storage is restricted so only authenticated users can read or write\ndata. To get started without setting up [Firebase Authentication](/docs/auth), you can\n[configure your rules for public access](/docs/storage/security/rules-conditions#public).\n\nThis does make Cloud Storage open to anyone, even people not using your\napp, so be sure to restrict your Cloud Storage again when you set up\nauthentication.\n\nAdd the Cloud Storage SDK to your app\n\n1. From the root of your Flutter project, run the following command to install\n the plugin:\n\n flutter pub add firebase_storage\n\n2. Once complete, rebuild your Flutter application:\n\n flutter run\n\n3. Import the plugin in your Dart code:\n\n import 'package:firebase_storage/firebase_storage.dart';\n\nSet up Cloud Storage\n\n1. Run `flutterfire configure` from your Flutter project directory. This\n updates the Firebase config file (`firebase_options.dart`) in your app's\n codebase so that it has the name of your default Cloud Storage bucket.\n\n | **Note:** Alternatively to updating your config file, you can explicitly specify the bucket name when you create an instance of `FirebaseStorage` (see next step). You can find the bucket name in the [Cloud Storage *Files* tab](https://console.firebase.google.com/project/_/storage/) of the Firebase console.\n2. Access your Cloud Storage bucket by creating an instance of\n `FirebaseStorage`:\n\n final storage = FirebaseStorage.instance;\n\n // Alternatively, explicitly specify the bucket name URL.\n // final storage = FirebaseStorage.instanceFor(bucket: \"gs://\u003cvar\u003eBUCKET_NAME\u003c/var\u003e\");\n\nYou're ready to start using Cloud Storage!\n\nNext step? Learn how to\n[create a Cloud Storage reference](/docs/storage/flutter/create-reference).\n\nAdvanced setup\n\nThere are a few use cases that require additional setup:\n\n- Using Cloud Storage buckets in [multiple geographic regions](//cloud.google.com/storage/docs/bucket-locations)\n- Using Cloud Storage buckets in [different storage classes](//cloud.google.com/storage/docs/storage-classes)\n- Using Cloud Storage buckets with multiple authenticated users in the same app\n\nThe first use case is perfect if you have users across the world, and want to\nstore their data near them. For instance, you can create buckets in the US,\nEurope, and Asia to store data for users in those regions to reduce latency.\n\nThe second use case is helpful if you have data with different access patterns.\nFor instance: you can set up a multi-regional or regional bucket that stores\npictures or other frequently accessed content, and a nearline or coldline bucket\nthat stores user backups or other infrequently accessed content.\n\nIn either of these use cases, you'll want to\n[use multiple Cloud Storage buckets](#use_multiple_storage_buckets).\n\nThe third use case is useful if you're building an app, like Google Drive, which\nlets users have multiple logged in accounts (for instance, a personal account\nand a work account). You can\n[use a custom Firebase App](#use_a_custom_firebaseapp)\ninstance to authenticate each additional account.\n\nUse multiple Cloud Storage buckets\n\nIf you want to use a Cloud Storage bucket other than the default provided above,\nor use multiple Cloud Storage buckets in a single app, you can create an instance\nof `FirebaseStorage` that references your custom bucket: \n\n // Get a non-default Storage bucket\n final storage = FirebaseStorage.instanceFor(bucket: \"gs://my-custom-bucket\");\n\nWorking with imported buckets\n\nWhen importing an existing Cloud Storage bucket into Firebase, you'll\nhave to grant Firebase the ability to access these files using the\n`gsutil` tool, included in the\n[Google Cloud SDK](//cloud.google.com/sdk/docs/): \n\n gsutil -m acl ch -r -u service-PROJECT_NUMBER@gcp-sa-firebasestorage.iam.gserviceaccount.com gs://YOUR-CLOUD-STORAGE-BUCKET\n\nYou can find your project number as described in the [introduction to\nFirebase projects](/docs/projects/learn-more#project-number).\n\nThis does not affect newly created buckets, as those have the default access\ncontrol set to allow Firebase. This is a temporary measure, and will be\nperformed automatically in the future.\n\nUse a custom Firebase App\n\nIf you're building a more complicated app using a custom `FirebaseApp`, you can\ncreate an instance of `FirebaseStorage` initialized with that app: \n\n // Use a non-default App\n final storage = FirebaseStorage.instanceFor(app: customApp);\n\nNext steps\n\n- Prepare to launch your app:\n - Enable [App Check](/docs/app-check) to help ensure that only your apps can access your storage buckets.\n - Set up [budget alerts](/docs/projects/billing/avoid-surprise-bills#set-up-budget-alert-emails) for your project in the Google Cloud Console.\n - Monitor the [*Usage and billing* dashboard](//console.firebase.google.com/project/_/usage) in the Firebase console to get an overall picture of your project's usage across multiple Firebase services. You can also visit the [Cloud Storage *Usage* dashboard](//console.firebase.google.com/project/_/storage/usage) for more detailed usage information.\n - Review the [Firebase launch checklist](/support/guides/launch-checklist)."]]