FirebaseStorage

public 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 methods

@NonNull FirebaseApp

The FirebaseApp associated with this FirebaseStorage instance.

static @NonNull FirebaseStorage

Returns the FirebaseStorage, initialized with the default FirebaseApp.

static @NonNull FirebaseStorage

Returns the FirebaseStorage, initialized with a custom FirebaseApp

static @NonNull FirebaseStorage

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

static @NonNull 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.

@NonNull StorageReference

Creates a new StorageReference initialized at the root Firebase Storage location.

@NonNull StorageReference

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

@NonNull StorageReference

Creates a StorageReference 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(@NonNull String host, int port)

Modifies this FirebaseStorage instance to communicate with the Storage emulator.

Public methods

getApp

public @NonNull FirebaseApp getApp()

The FirebaseApp associated with this FirebaseStorage instance.

getInstance

public static @NonNull FirebaseStorage getInstance()

Returns the FirebaseStorage, initialized with the default FirebaseApp.

Returns
@NonNull FirebaseStorage

a FirebaseStorage instance.

getInstance

public static @NonNull FirebaseStorage getInstance(@NonNull FirebaseApp app)

Returns the FirebaseStorage, initialized with a custom FirebaseApp

Parameters
@NonNull FirebaseApp app

The custom FirebaseApp used for initialization.

Returns
@NonNull FirebaseStorage

a FirebaseStorage instance.

getInstance

public static @NonNull FirebaseStorage getInstance(@NonNull String url)

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

Parameters
@NonNull String url

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

Returns
@NonNull FirebaseStorage

a FirebaseStorage instance.

getInstance

public static @NonNull FirebaseStorage getInstance(@NonNull FirebaseApp app, @NonNull String url)

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

Parameters
@NonNull FirebaseApp app

The custom FirebaseApp used for initialization.

@NonNull String url

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

Returns
@NonNull FirebaseStorage

a FirebaseStorage instance.

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 @NonNull StorageReference getReference()

Creates a new StorageReference initialized at the root Firebase Storage location.

Returns
@NonNull StorageReference

An instance of StorageReference.

getReference

public @NonNull StorageReference getReference(@NonNull String location)

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

Parameters
@NonNull String location

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

Returns
@NonNull StorageReference

An instance of StorageReference at the given child path.

getReferenceFromUrl

public @NonNull StorageReference getReferenceFromUrl(@NonNull String fullUrl)

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

Parameters
@NonNull String fullUrl

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

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(@NonNull String 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
@NonNull String host

the emulator host (for example, 10.0.2.2)

int port

the emulator port (for example, 9000)