FirebaseStorage

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 functions

FirebaseApp

TheFirebaseApp associated with thisFirebaseStorage instance.

java-staticFirebaseStorage

Returns theFirebaseStorage, initialized with the defaultFirebaseApp.

java-staticFirebaseStorage

Returns theFirebaseStorage, initialized with a customFirebaseApp

java-staticFirebaseStorage

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

java-staticFirebaseStorage

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.

StorageReference

Creates a newStorageReference initialized at the root Firebase Storage location.

StorageReference
getReference(location: String)

Creates a newStorageReference initialized with a child Firebase Storage location.

StorageReference

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

Unit
setMaxChunkUploadRetry(maxChunkRetryMillis: Long)

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

Unit
setMaxDownloadRetryTimeMillis(maxTransferRetryMillis: Long)

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

Unit
setMaxOperationRetryTimeMillis(maxTransferRetryMillis: Long)

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

Unit
setMaxUploadRetryTimeMillis(maxTransferRetryMillis: Long)

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

Unit
useEmulator(host: String, port: Int)

Modifies this FirebaseStorage instance to communicate with the Storage emulator.

Public functions

getApp

fun getApp(): FirebaseApp

TheFirebaseApp associated with thisFirebaseStorage instance.

getInstance

java-static fun getInstance(): FirebaseStorage

Returns theFirebaseStorage, initialized with the defaultFirebaseApp.

getInstance

java-static fun getInstance(app: FirebaseApp): FirebaseStorage

Returns theFirebaseStorage, initialized with a customFirebaseApp

Parameters
app: FirebaseApp

The customFirebaseApp used for initialization.

getInstance

java-static fun getInstance(url: String): FirebaseStorage

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

Parameters
url: String

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

getInstance

java-static fun getInstance(app: FirebaseApp, url: String): FirebaseStorage

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

Parameters
app: FirebaseApp

The customFirebaseApp used for initialization.

url: String

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

getMaxChunkUploadRetry

fun getMaxChunkUploadRetry(): Long

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

Returns
Long

maximum time in milliseconds. Defaults to 1 minute.

getMaxDownloadRetryTimeMillis

fun getMaxDownloadRetryTimeMillis(): Long

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

fun getMaxOperationRetryTimeMillis(): Long

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

fun getMaxUploadRetryTimeMillis(): Long

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

fun getReference(): StorageReference

Creates a newStorageReference initialized at the root Firebase Storage location.

Returns
StorageReference

An instance ofStorageReference.

getReference

fun getReference(location: String): StorageReference

Creates a newStorageReference initialized with a child Firebase Storage location.

Parameters
location: String

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

Returns
StorageReference

An instance ofStorageReference at the given child path.

getReferenceFromUrl

fun getReferenceFromUrl(fullUrl: String): StorageReference

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

Parameters
fullUrl: String

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

fun setMaxChunkUploadRetry(maxChunkRetryMillis: Long): Unit

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

Parameters
maxChunkRetryMillis: Long

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

setMaxDownloadRetryTimeMillis

fun setMaxDownloadRetryTimeMillis(maxTransferRetryMillis: Long): Unit

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

Parameters
maxTransferRetryMillis: Long

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

setMaxOperationRetryTimeMillis

fun setMaxOperationRetryTimeMillis(maxTransferRetryMillis: Long): Unit

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

Parameters
maxTransferRetryMillis: Long

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

setMaxUploadRetryTimeMillis

fun setMaxUploadRetryTimeMillis(maxTransferRetryMillis: Long): Unit

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

Parameters
maxTransferRetryMillis: Long

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

useEmulator

fun useEmulator(host: String, port: Int): Unit

Modifies this FirebaseStorage instance to communicate with the Storage emulator.

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

Parameters
host: String

the emulator host (for example, 10.0.2.2)

port: Int

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.