Mantenha tudo organizado com as coleções Salve e categorize o conteúdo com base nas suas preferências.
O Cloud Storage for Firebase armazena seus dados em um bucket do Google Cloud Storage, uma solução de armazenamento de objetos em escala de exabytes com alta disponibilidade e redundância global. O SDK Admin do Firebase permite acessar diretamente os buckets do Cloud Storage de ambientes privilegiados. Então, é possível usar APIs do Google Cloud Storage para manipular os objetos armazenados nos buckets.
O Admin SDK também permite criar URLs compartilháveis para que os usuários possam baixar objetos nos buckets.
Usar um bucket padrão
Você pode especificar um nome de bucket padrão ao inicializar o SDK Admin. Com isso, é possível recuperar uma referência autenticada para esse bucket.
O nome do bucket não pode conter gs:// ou qualquer outro prefixo de protocolo. Por exemplo, se o URL do bucket exibido no console do Firebase for gs://PROJECT_ID.firebasestorage.app, transmita a string PROJECT_ID.firebasestorage.app ao SDK Admin.
Node.js
const{initializeApp,cert}=require('firebase-admin/app');const{getStorage}=require('firebase-admin/storage');constserviceAccount=require('./path/to/serviceAccountKey.json');initializeApp({credential:cert(serviceAccount),storageBucket:'<BUCKET_NAME>.appspot.com'});constbucket=getStorage().bucket();// 'bucket' is an object defined in the @google-cloud/storage library.// See https://googlecloudplatform.github.io/google-cloud-node/#/docs/storage/latest/storage/bucket// for more details.
Java
FileInputStreamserviceAccount=newFileInputStream("path/to/serviceAccountKey.json");FirebaseOptionsoptions=FirebaseOptions.builder().setCredentials(GoogleCredentials.fromStream(serviceAccount)).setStorageBucket("<BUCKET_NAME>.appspot.com").build();FirebaseApp.initializeApp(options);Bucketbucket=StorageClient.getInstance().bucket();// 'bucket' is an object defined in the google-cloud-storage Java library.// See https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Bucket// for more details.
Python
importfirebase_adminfromfirebase_adminimportcredentialsfromfirebase_adminimportstoragecred=credentials.Certificate('path/to/serviceAccountKey.json')firebase_admin.initialize_app(cred,{'storageBucket':'PROJECT_ID.firebasestorage.app'})bucket=storage.bucket()# 'bucket' is an object defined in the google-cloud-storage Python library.# See https://googlecloudplatform.github.io/google-cloud-python/latest/storage/buckets.html# for more details.
Go
import("context""log"firebase"firebase.google.com/go/v4""firebase.google.com/go/v4/auth""google.golang.org/api/option")config:=&firebase.Config{StorageBucket:"<BUCKET_NAME>.appspot.com",}opt:=option.WithCredentialsFile("path/to/serviceAccountKey.json")app,err:=firebase.NewApp(context.Background(),config,opt)iferr!=nil{log.Fatalln(err)}client,err:=app.Storage(context.Background())iferr!=nil{log.Fatalln(err)}bucket,err:=client.DefaultBucket()iferr!=nil{log.Fatalln(err)}// 'bucket' is an object defined in the cloud.google.com/go/storage package.// See https://godoc.org/cloud.google.com/go/storage#BucketHandle// for more details.
É possível usar as referências do bucket retornadas pelo SDK Admin com as bibliotecas de cliente do Google Cloud Storage oficiais para baixar, fazer upload e modificar o conteúdo nos buckets associados aos projetos do Firebase. Não é necessário autenticar as bibliotecas do Google Cloud Storage ao usar o SDK Admin do Firebase. As referências de bucket retornadas pelo SDK Admin já foram autenticadas com as credenciais usadas para inicializar seu app do Firebase.
Usar buckets personalizados
Para usar um bucket Cloud Storage diferente do padrão descrito anteriormente neste guia ou vários buckets Cloud Storage em um único app, recupere uma referência a um bucket personalizado:
Ao criar um app mais complicado que interage com vários apps do Firebase, é possível acessar os buckets Cloud Storage associados a um app específico do Firebase da seguinte maneira:
É possível usar o Admin SDK para gerar um URL de download que não expira para arquivos armazenados nos buckets. Qualquer pessoa com esse URL pode acessar o arquivo permanentemente.
Os SDKs Admin do Firebase dependem das bibliotecas de cliente do Google Cloud Storage para dar acesso ao Cloud Storage. As referências do bucket retornadas pelo SDK Admin são objetos definidos nessas bibliotecas. Consulte a documentação e as Referências de API das bibliotecas de cliente do Google Cloud Storage para saber como usar as referências de bucket retornadas em casos de uso, por exemplo, para upload e download de um arquivo.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Não contém as informações de que eu preciso","missingTheInformationINeed","thumb-down"],["Muito complicado / etapas demais","tooComplicatedTooManySteps","thumb-down"],["Desatualizado","outOfDate","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Problema com as amostras / o código","samplesCodeIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-13 UTC."],[],[],null,["\u003cbr /\u003e\n\nCloud Storage for Firebase stores your data in a\n[Google Cloud Storage](//cloud.google.com/storage) bucket --- an\nexabyte scale object storage solution with high availability and global\nredundancy. The Firebase Admin SDK allows you to directly access your\nCloud Storage buckets from privileged environments. Then you can use\n[Google Cloud Storage APIs](//cloud.google.com/storage/docs/reference/libraries)\nto manipulate the objects stored in the buckets.\n\nThe Admin SDK also lets you to create shareable URLs so users can\ndownload objects in your buckets.\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\nUse a default bucket\n\nYou can specify a default bucket name when initializing the Admin SDK. Then you\ncan retrieve an authenticated reference to this bucket.\n\nThe bucket name must *not* contain `gs://` or any other protocol prefixes.\nFor example, if the bucket URL displayed in the\n[Firebase console](//console.firebase.google.com/project/_/storage)\nis `gs://`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.firebasestorage.app`, pass the string\n\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.firebasestorage.app` to the Admin SDK. \n\nNode.js \n\n const { initializeApp, cert } = require('firebase-admin/app');\n const { getStorage } = require('firebase-admin/storage');\n\n const serviceAccount = require('./path/to/serviceAccountKey.json');\n\n initializeApp({\n credential: cert(serviceAccount),\n storageBucket: '\u003cBUCKET_NAME\u003e.appspot.com'\n });\n\n const bucket = getStorage().bucket();\n\n // 'bucket' is an object defined in the @google-cloud/storage library.\n // See https://googlecloudplatform.github.io/google-cloud-node/#/docs/storage/latest/storage/bucket\n // for more details.\n\nJava \n\n FileInputStream serviceAccount = new FileInputStream(\"path/to/serviceAccountKey.json\");\n\n FirebaseOptions options = FirebaseOptions.builder()\n .setCredentials(GoogleCredentials.fromStream(serviceAccount))\n .setStorageBucket(\"\u003cBUCKET_NAME\u003e.appspot.com\")\n .build();\n FirebaseApp.initializeApp(options);\n\n Bucket bucket = StorageClient.getInstance().bucket();\n\n // 'bucket' is an object defined in the google-cloud-storage Java library.\n // See https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Bucket\n // for more details.\n\nPython \n\n import firebase_admin\n from firebase_admin import credentials\n from firebase_admin import storage\n\n cred = credentials.Certificate('path/to/serviceAccountKey.json')\n firebase_admin.initialize_app(cred, {\n 'storageBucket': '\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e.firebasestorage.app'\n })\n\n bucket = storage.bucket()\n\n # 'bucket' is an object defined in the google-cloud-storage Python library.\n # See https://googlecloudplatform.github.io/google-cloud-python/latest/storage/buckets.html\n # for more details.\n\nGo \n\n import (\n \t\"context\"\n \t\"log\"\n\n \tfirebase \"firebase.google.com/go/v4\"\n \t\"firebase.google.com/go/v4/auth\"\n \t\"google.golang.org/api/option\"\n )\n\n config := &firebase.Config{\n \tStorageBucket: \"\u003cBUCKET_NAME\u003e.appspot.com\",\n }\n opt := option.WithCredentialsFile(\"path/to/serviceAccountKey.json\")\n app, err := firebase.NewApp(context.Background(), config, opt)\n if err != nil {\n \tlog.Fatalln(err)\n }\n\n client, err := app.Storage(context.Background())\n if err != nil {\n \tlog.Fatalln(err)\n }\n\n bucket, err := client.DefaultBucket()\n if err != nil {\n \tlog.Fatalln(err)\n }\n // 'bucket' is an object defined in the cloud.google.com/go/storage package.\n // See https://godoc.org/cloud.google.com/go/storage#BucketHandle\n // for more details. \n https://github.com/firebase/firebase-admin-go/blob/26dec0b7589ef7641eefd6681981024079b8524c/snippets/storage.go#L31-L51\n\nYou can use the bucket references returned by the Admin SDK in conjunction with\nthe official\n[Google Cloud Storage client libraries](//cloud.google.com/storage/docs/reference/libraries)\nto upload, download, and modify content in the buckets associated with your\nFirebase projects. Note that you do not have to authenticate\nGoogle Cloud Storage libraries when using the Firebase Admin SDK. The bucket\nreferences returned by the Admin SDK are already authenticated with the\ncredentials used to initialize your Firebase app.\n\nUse custom buckets\n\nIf you want to use a Cloud Storage bucket other than the default bucket\ndescribed earlier in this guide, or use multiple Cloud Storage buckets in\na single app, you can retrieve a reference to a custom bucket: \n\nNode.js \n\n const bucket = getStorage().bucket('my-custom-bucket');\n\nJava \n\n Bucket bucket = StorageClient.getInstance().bucket(\"my-custom-bucket\");\n\nPython \n\n bucket = storage.bucket('my-custom-bucket')\n\nGo \n\n bucket, err := client.Bucket(\"my-custom-bucket\") \n https://github.com/firebase/firebase-admin-go/blob/26dec0b7589ef7641eefd6681981024079b8524c/snippets/storage.go#L64-L64\n\nUse a custom Firebase app\n\nIf you are building a more complicated application that interacts with\n[multiple Firebase apps](/docs/admin/setup#initialize-multiple-apps), you can\naccess the Cloud Storage buckets associated with a specific Firebase app\nas follows: \n\nNode.js \n\n const bucket = getStorage(customApp).bucket();\n\nJava \n\n Bucket bucket = StorageClient.getInstance(customApp).bucket();\n\nPython \n\n bucket = storage.bucket(app=custom_app)\n\nGo \n\n otherClient, err := otherApp.Storage(context.Background())\n bucket, err := otherClient.Bucket(\"other-app-bucket\")\n\nGet a shareable download URL\n\nYou can use the Admin SDK to generate a non-expiring download URL for\nfiles stored in your buckets. Anyone with this URL can permanently\naccess the file. \n\nNode.js \n\n const { getStorage, getDownloadURL } = require('firebase-admin/storage');\n\n const fileRef = getStorage().bucket('my-bucket').file('my-file');\n const downloadURL= await getDownloadURL(fileRef);\n\nGoogle Cloud Storage client libraries\n\nThe Firebase Admin SDKs depend on the\n[Google Cloud Storage client libraries](//cloud.google.com/storage/docs/reference/libraries)\nto provide Cloud Storage access. The bucket references returned by the\nAdmin SDK are objects defined in these libraries. Refer to the documentation and\nAPI references of the Google Cloud Storage client libraries to learn how to\nuse the returned bucket references in use cases like file\n[upload](//cloud.google.com/storage/docs/uploading-objects) and\n[download](//cloud.google.com/storage/docs/downloading-objects)."]]