FirebaseStorage

class FirebaseStorage


FirebaseStorage is a service that supports uploading and downloading large objects to Google Cloud Storage. Pass a custom instance of FirebaseApp to getInstance which will initialize it with a storage location (bucket) specified via setStorageBucket.

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

Summary

Public functions

FirebaseApp

The FirebaseApp associated with this FirebaseStorage instance.

java-static FirebaseStorage

Returns the FirebaseStorage, initialized with the default FirebaseApp.

java-static FirebaseStorage

Returns the FirebaseStorage, initialized with a custom FirebaseApp

java-static FirebaseStorage

Returns the FirebaseStorage, initialized with the default FirebaseApp and a custom Storage Bucket.

java-static FirebaseStorage

Returns the FirebaseStorage, initialized with a custom FirebaseApp 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 new StorageReference initialized at the root Firebase Storage location.

StorageReference
getReference(location: String)

Creates a new StorageReference initialized with a child Firebase Storage location.

StorageReference

Creates a StorageReference 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

The FirebaseApp associated with this FirebaseStorage instance.

getInstance

java-static fun getInstance(): FirebaseStorage

Returns the FirebaseStorage, initialized with the default FirebaseApp.

Returns
FirebaseStorage

a FirebaseStorage instance.

getInstance

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

Returns the FirebaseStorage, initialized with a custom FirebaseApp

Parameters
app: FirebaseApp

The custom FirebaseApp used for initialization.

Returns
FirebaseStorage

a FirebaseStorage instance.

getInstance

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

Returns the FirebaseStorage, initialized with the default FirebaseApp and a custom Storage Bucket.

Parameters
url: String

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

Returns
FirebaseStorage

a FirebaseStorage instance.

getInstance

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

Returns the FirebaseStorage, initialized with a custom FirebaseApp and a custom Storage Bucket.

Parameters
app: FirebaseApp

The custom FirebaseApp used for initialization.

url: String

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

Returns
FirebaseStorage

a FirebaseStorage instance.

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 new StorageReference initialized at the root Firebase Storage location.

Returns
StorageReference

An instance of StorageReference.

getReference

fun getReference(location: String): StorageReference

Creates a new StorageReference 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 of StorageReference at the given child path.

getReferenceFromUrl

fun getReferenceFromUrl(fullUrl: String): StorageReference

Creates a StorageReference 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 from getDownloadUrl or the uri retrieved from toString An error is thrown if fullUrl is not associated with the FirebaseApp used to initialize this FirebaseStorage.

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)