FirebaseStorage

public classFirebaseStorage


FirebaseStorage is a service that supports uploading and downloading large objects to Google Cloud Storage. Pass a custom instance ofFirebaseApp togetInstance which will initialize it with a storage location (bucket) specified viasetStorageBucket.

Otherwise, if you callgetReference without a FirebaseApp, the FirebaseStorage instance will initialize with the defaultFirebaseApp obtainable fromgetInstance. The storage location in this case will come the JSON configuration file downloaded from the web.

Summary

Public methods

@NonNullFirebaseApp

TheFirebaseApp associated with thisFirebaseStorage instance.

static @NonNullFirebaseStorage

Returns theFirebaseStorage, initialized with the defaultFirebaseApp.

static @NonNullFirebaseStorage

Returns theFirebaseStorage, initialized with a customFirebaseApp

static @NonNullFirebaseStorage

Returns theFirebaseStorage, initialized with the defaultFirebaseApp and a custom Storage Bucket.

static @NonNullFirebaseStorage

Returns theFirebaseStorage, initialized with a customFirebaseApp and a custom Storage Bucket.

long

Returns the maximum time to retry sending a chunk if a failure occurs

long

Returns the maximum time to retry a download if a failure occurs.

long

Returns the maximum time to retry operations other than upload and download if a failure occurs.

long

Returns the maximum time to retry an upload if a failure occurs.

@NonNullStorageReference

Creates a newStorageReference initialized at the root Firebase Storage location.

@NonNullStorageReference

Creates a newStorageReference initialized with a child Firebase Storage location.

@NonNullStorageReference

Creates aStorageReference given a gs:// or https:// URL pointing to a Firebase Storage location.

void
setMaxChunkUploadRetry(long maxChunkRetryMillis)

Sets the maximum time to retry sending a chunk if a failure occurs

void
setMaxDownloadRetryTimeMillis(long maxTransferRetryMillis)

Sets the maximum time to retry a download if a failure occurs.

void
setMaxOperationRetryTimeMillis(long maxTransferRetryMillis)

Sets the maximum time to retry operations other than upload and download if a failure occurs.

void
setMaxUploadRetryTimeMillis(long maxTransferRetryMillis)

Sets the maximum time to retry an upload if a failure occurs.

void
useEmulator(@NonNullString host, int port)

Modifies this FirebaseStorage instance to communicate with the Storage emulator.

Public methods

getApp

public @NonNullFirebaseApp getApp()

TheFirebaseApp associated with thisFirebaseStorage instance.

getInstance

public static @NonNullFirebaseStorage getInstance()

Returns theFirebaseStorage, initialized with the defaultFirebaseApp.

getInstance

public static @NonNullFirebaseStorage getInstance(@NonNullFirebaseApp app)

Returns theFirebaseStorage, initialized with a customFirebaseApp

Parameters
@NonNullFirebaseApp app

The customFirebaseApp used for initialization.

getInstance

public static @NonNullFirebaseStorage getInstance(@NonNullString url)

Returns theFirebaseStorage, initialized with the defaultFirebaseApp and a custom Storage Bucket.

Parameters
@NonNullString url

The gs:// url to your Firebase Storage Bucket.

getInstance

public static @NonNullFirebaseStorage getInstance(@NonNullFirebaseApp app, @NonNullString url)

Returns theFirebaseStorage, initialized with a customFirebaseApp and a custom Storage Bucket.

Parameters
@NonNullFirebaseApp app

The customFirebaseApp used for initialization.

@NonNullString url

The gs:// url to your Firebase Storage Bucket.

getMaxChunkUploadRetry

public long getMaxChunkUploadRetry()

Returns the maximum time to retry sending a chunk if a failure occurs

Returns
long

maximum time in milliseconds. Defaults to 1 minute.

getMaxDownloadRetryTimeMillis

public long getMaxDownloadRetryTimeMillis()

Returns the maximum time to retry a download if a failure occurs.

Returns
long

maximum time in milliseconds. Defaults to 10 minutes (600,000 milliseconds).

getMaxOperationRetryTimeMillis

public long getMaxOperationRetryTimeMillis()

Returns the maximum time to retry operations other than upload and download if a failure occurs.

Returns
long

the maximum time in milliseconds. Defaults to 2 minutes (120,000 milliseconds).

getMaxUploadRetryTimeMillis

public long getMaxUploadRetryTimeMillis()

Returns the maximum time to retry an upload if a failure occurs.

Returns
long

the maximum time in milliseconds. Defaults to 10 minutes (600,000 milliseconds).

getReference

public @NonNullStorageReference getReference()

Creates a newStorageReference initialized at the root Firebase Storage location.

getReference

public @NonNullStorageReference getReference(@NonNullString location)

Creates a newStorageReference initialized with a child Firebase Storage location.

Parameters
@NonNullString location

A relative path from the root to initialize the reference with, for instance "path/to/object"

Returns
@NonNullStorageReference

An instance ofStorageReference at the given child path.

getReferenceFromUrl

public @NonNullStorageReference getReferenceFromUrl(@NonNullString fullUrl)

Creates aStorageReference given a gs:// or https:// URL pointing to a Firebase Storage location.

Parameters
@NonNullString fullUrl

A gs:// or http[s]:// URL used to initialize the reference. For example, you can pass in a download URL retrieved fromgetDownloadUrl or the uri retrieved fromtoString An error is thrown if fullUrl is not associated with theFirebaseApp used to initialize thisFirebaseStorage.

setMaxChunkUploadRetry

public void setMaxChunkUploadRetry(long maxChunkRetryMillis)

Sets the maximum time to retry sending a chunk if a failure occurs

Parameters
long maxChunkRetryMillis

the maximum time in milliseconds. Defaults to 1 minute (60,000 milliseconds).

setMaxDownloadRetryTimeMillis

public void setMaxDownloadRetryTimeMillis(long maxTransferRetryMillis)

Sets the maximum time to retry a download if a failure occurs.

Parameters
long maxTransferRetryMillis

the maximum time in milliseconds. Defaults to 10 minutes (600,000 milliseconds).

setMaxOperationRetryTimeMillis

public void setMaxOperationRetryTimeMillis(long maxTransferRetryMillis)

Sets the maximum time to retry operations other than upload and download if a failure occurs.

Parameters
long maxTransferRetryMillis

the maximum time in milliseconds. Defaults to 2 minutes (120,000 milliseconds).

setMaxUploadRetryTimeMillis

public void setMaxUploadRetryTimeMillis(long maxTransferRetryMillis)

Sets the maximum time to retry an upload if a failure occurs.

Parameters
long maxTransferRetryMillis

the maximum time in milliseconds. Defaults to 10 minutes (600,000 milliseconds).

useEmulator

public void useEmulator(@NonNullString host, int port)

Modifies this FirebaseStorage instance to communicate with the Storage emulator.

Note: Call this method before using the instance to do any storage operations.

Parameters
@NonNullString host

the emulator host (for example, 10.0.2.2)

int port

the emulator port (for example, 9000)

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.