Cloud Storage

Cloud Storage for Firebase stores your data in Google Cloud Storage, an exabyte scale object storage solution with high availability and global redundancy.

This SDK provides a bridge to the google/cloud-storage package. You can enable the component in the SDK by adding the package to your project dependencies:

Before you start, please read about Firebase Cloud Storage in the official documentation:

Initializing the Storage component

With the SDK

$storage = $factory->createStorage();

With Dependency Injection (Symfony Bundle/Laravel/Lumen Package)

use Kreait\Firebase\Contract\Storage;

class MyService
{
    public function __construct(Storage $storage)
    {
        $this->storage = $storage;
    }
}

With the Laravel app() helper (Laravel/Lumen Package)

$storage = app('firebase.storage');

Getting started

$storageClient = $storage->getStorageClient();
$defaultBucket = $storage->getBucket();
$anotherBucket = $storage->getBucket('another-bucket');

Default Storage bucket

Note

It is not necessary to change the default storage bucket in most cases.

The SDK assumes that your project’s default storage bucket name has the format <project-id>.appspot.com and will configure the storage instance accordingly.

If you want to change the default bucket your instance works with, you can specify the name when using the factory:

use Kreait\Firebase\Factory;

$storage = (new Factory())
    ->withDefaultStorageBucket('another-default-bucket')
    ->createStorage();