Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference {% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %} # storage package Cloud Storage for Firebase ## Functions | Function | Description | | --- | --- | | function(app, ...) | | [getStorage(app, bucketUrl)](./storage.md#getstorage_25f3a57) | Gets a [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance for the given Firebase app. | | function(storage, ...) | | [connectStorageEmulator(storage, host, port, options)](./storage.md#connectstorageemulator_e9039de) | Modify this [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance to communicate with the Cloud Storage emulator. | | [ref(storage, url)](./storage.md#ref_5672fc1) | Returns a [StorageReference](./storage.storagereference.md#storagereference_interface) for the given url. | | function(ref, ...) | | [deleteObject(ref)](./storage.md#deleteobject_30df0b2) | Deletes the object at this location. | | [getBlob(ref, maxDownloadSizeBytes)](./storage.md#getblob_1c7a935) | Downloads the data at the object's location. Returns an error if the object is not found.To use this functionality, you have to whitelist your app's origin in your Cloud Storage bucket. See also https://cloud.google.com/storage/docs/configuring-corsThis API is not available in Node. | | [getBytes(ref, maxDownloadSizeBytes)](./storage.md#getbytes_1c7a935) | Downloads the data at the object's location. Returns an error if the object is not found.To use this functionality, you have to whitelist your app's origin in your Cloud Storage bucket. See also https://cloud.google.com/storage/docs/configuring-cors | | [getDownloadURL(ref)](./storage.md#getdownloadurl_30df0b2) | Returns the download URL for the given [StorageReference](./storage.storagereference.md#storagereference_interface). | | [getMetadata(ref)](./storage.md#getmetadata_30df0b2) | A Promise that resolves with the metadata for this object. If this object doesn't exist or metadata cannot be retrieved, the promise is rejected. | | [getStream(ref, maxDownloadSizeBytes)](./storage.md#getstream_1c7a935) | Downloads the data at the object's location. Raises an error event if the object is not found.This API is only available in Node. | | [list(ref, options)](./storage.md#list_36af757) | List items (files) and prefixes (folders) under this storage reference.List API is only available for Firebase Rules Version 2.GCS is a key-blob store. Firebase Storage imposes the semantic of '/' delimited folder structure. Refer to GCS's List API if you want to learn more.To adhere to Firebase Rules's Semantics, Firebase Storage does not support objects whose paths end with "/" or contain two consecutive "/"s. Firebase Storage List API will filter these unsupported objects. list() may fail if there are too many unsupported objects in the bucket. | | [listAll(ref)](./storage.md#listall_30df0b2) | List all items (files) and prefixes (folders) under this storage reference.This is a helper method for calling list() repeatedly until there are no more results. The default pagination size is 1000.Note: The results may not be consistent if objects are changed while this operation is running.Warning: listAll may potentially consume too many resources if there are too many results. | | [updateMetadata(ref, metadata)](./storage.md#updatemetadata_a634608) | Updates the metadata for this object. | | [uploadBytes(ref, data, metadata)](./storage.md#uploadbytes_02686b1) | Uploads data to this object's location. The upload is not resumable. | | [uploadBytesResumable(ref, data, metadata)](./storage.md#uploadbytesresumable_02686b1) | Uploads data to this object's location. The upload can be paused and resumed, and exposes progress updates. | | [uploadString(ref, value, format, metadata)](./storage.md#uploadstring_277829d) | Uploads a string to this object's location. The upload is not resumable. | | function(storageOrRef, ...) | | [ref(storageOrRef, path)](./storage.md#ref_41be95d) | Returns a [StorageReference](./storage.storagereference.md#storagereference_interface) for the given path in the default bucket. | ## Classes | Class | Description | | --- | --- | | [StorageError](./storage.storageerror.md#storageerror_class) | An error returned by the Firebase Storage SDK. | ## Enumerations | Enumeration | Description | | --- | --- | | [StorageErrorCode](./storage.md#storageerrorcode) | Error codes that can be attached to StorageError objects. | ## Interfaces | Interface | Description | | --- | --- | | [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) | A Firebase Storage instance. | | [FullMetadata](./storage.fullmetadata.md#fullmetadata_interface) | The full set of object metadata, including read-only properties. | | [ListOptions](./storage.listoptions.md#listoptions_interface) | The options list() accepts. | | [ListResult](./storage.listresult.md#listresult_interface) | Result returned by list(). | | [SettableMetadata](./storage.settablemetadata.md#settablemetadata_interface) | Object metadata that can be set at any time. | | [StorageObserver](./storage.storageobserver.md#storageobserver_interface) | A stream observer for Firebase Storage. | | [StorageReference](./storage.storagereference.md#storagereference_interface) | Represents a reference to a Google Cloud Storage object. Developers can upload, download, and delete objects, as well as get/set object metadata. | | [UploadMetadata](./storage.uploadmetadata.md#uploadmetadata_interface) | Object metadata that can be set at upload. | | [UploadResult](./storage.uploadresult.md#uploadresult_interface) | Result returned from a non-resumable upload. | | [UploadTask](./storage.uploadtask.md#uploadtask_interface) | Represents the process of uploading an object. Allows you to monitor and manage the upload. | | [UploadTaskSnapshot](./storage.uploadtasksnapshot.md#uploadtasksnapshot_interface) | Holds data about the current state of the upload task. | ## Variables | Variable | Description | | --- | --- | | [StringFormat](./storage.md#stringformat) | An enumeration of the possible string formats for upload. | ## Type Aliases | Type Alias | Description | | --- | --- | | [StringFormat](./storage.md#stringformat) | An enumeration of the possible string formats for upload. | | [TaskEvent](./storage.md#taskevent) | An event that is triggered on a task. | | [TaskState](./storage.md#taskstate) | Represents the current state of a running upload. | ## function(app, ...) ### getStorage(app, bucketUrl) {:#getstorage_25f3a57} Gets a [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance for the given Firebase app. Signature: ```typescript export declare function getStorage(app?: FirebaseApp, bucketUrl?: string): FirebaseStorage; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | Firebase app to get [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance for. | | bucketUrl | string | The gs:// url to your Firebase Storage Bucket. If not passed, uses the app's default Storage Bucket. | Returns: [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) A [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance. ## function(storage, ...) ### connectStorageEmulator(storage, host, port, options) {:#connectstorageemulator_e9039de} Modify this [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance to communicate with the Cloud Storage emulator. Signature: ```typescript export declare function connectStorageEmulator(storage: FirebaseStorage, host: string, port: number, options?: { mockUserToken?: EmulatorMockTokenOptions | string; }): void; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | storage | [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) | The [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance | | host | string | The emulator host (ex: localhost) | | port | number | The emulator port (ex: 5001) | | options | { mockUserToken?: [EmulatorMockTokenOptions](./util.md#emulatormocktokenoptions) \| string; } | Emulator options. options.mockUserToken is the mock auth token to use for unit testing Security Rules. | Returns: void ### ref(storage, url) {:#ref_5672fc1} Returns a [StorageReference](./storage.storagereference.md#storagereference_interface) for the given url. Signature: ```typescript export declare function ref(storage: FirebaseStorage, url?: string): StorageReference; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | storage | [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) | [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance. | | url | string | URL. If empty, returns root reference. | Returns: [StorageReference](./storage.storagereference.md#storagereference_interface) ## function(ref, ...) ### deleteObject(ref) {:#deleteobject_30df0b2} Deletes the object at this location. Signature: ```typescript export declare function deleteObject(ref: StorageReference): Promise; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | [StorageReference](./storage.storagereference.md#storagereference_interface) for object to delete. | Returns: Promise<void> A `Promise` that resolves if the deletion succeeds. ### getBlob(ref, maxDownloadSizeBytes) {:#getblob_1c7a935} Downloads the data at the object's location. Returns an error if the object is not found. To use this functionality, you have to whitelist your app's origin in your Cloud Storage bucket. See also https://cloud.google.com/storage/docs/configuring-cors This API is not available in Node. Signature: ```typescript export declare function getBlob(ref: StorageReference, maxDownloadSizeBytes?: number): Promise; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | StorageReference where data should be downloaded. | | maxDownloadSizeBytes | number | If set, the maximum allowed size in bytes to retrieve. | Returns: Promise<Blob> A Promise that resolves with a Blob containing the object's bytes ### getBytes(ref, maxDownloadSizeBytes) {:#getbytes_1c7a935} Downloads the data at the object's location. Returns an error if the object is not found. To use this functionality, you have to whitelist your app's origin in your Cloud Storage bucket. See also https://cloud.google.com/storage/docs/configuring-cors Signature: ```typescript export declare function getBytes(ref: StorageReference, maxDownloadSizeBytes?: number): Promise; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | StorageReference where data should be downloaded. | | maxDownloadSizeBytes | number | If set, the maximum allowed size in bytes to retrieve. | Returns: Promise<ArrayBuffer> A Promise containing the object's bytes ### getDownloadURL(ref) {:#getdownloadurl_30df0b2} Returns the download URL for the given [StorageReference](./storage.storagereference.md#storagereference_interface). Signature: ```typescript export declare function getDownloadURL(ref: StorageReference): Promise; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | [StorageReference](./storage.storagereference.md#storagereference_interface) to get the download URL for. | Returns: Promise<string> A `Promise` that resolves with the download URL for this object. ### getMetadata(ref) {:#getmetadata_30df0b2} A `Promise` that resolves with the metadata for this object. If this object doesn't exist or metadata cannot be retrieved, the promise is rejected. Signature: ```typescript export declare function getMetadata(ref: StorageReference): Promise; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | [StorageReference](./storage.storagereference.md#storagereference_interface) to get metadata from. | Returns: Promise<[FullMetadata](./storage.fullmetadata.md#fullmetadata_interface)> ### getStream(ref, maxDownloadSizeBytes) {:#getstream_1c7a935} Downloads the data at the object's location. Raises an error event if the object is not found. This API is only available in Node. Signature: ```typescript export declare function getStream(ref: StorageReference, maxDownloadSizeBytes?: number): ReadableStream; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | StorageReference where data should be downloaded. | | maxDownloadSizeBytes | number | If set, the maximum allowed size in bytes to retrieve. | Returns: ReadableStream A stream with the object's data as bytes ### list(ref, options) {:#list_36af757} List items (files) and prefixes (folders) under this storage reference. List API is only available for Firebase Rules Version 2. GCS is a key-blob store. Firebase Storage imposes the semantic of '/' delimited folder structure. Refer to GCS's List API if you want to learn more. To adhere to Firebase Rules's Semantics, Firebase Storage does not support objects whose paths end with "/" or contain two consecutive "/"s. Firebase Storage List API will filter these unsupported objects. list() may fail if there are too many unsupported objects in the bucket. Signature: ```typescript export declare function list(ref: StorageReference, options?: ListOptions): Promise; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | [StorageReference](./storage.storagereference.md#storagereference_interface) to get list from. | | options | [ListOptions](./storage.listoptions.md#listoptions_interface) | See [ListOptions](./storage.listoptions.md#listoptions_interface) for details. | Returns: Promise<[ListResult](./storage.listresult.md#listresult_interface)> A `Promise` that resolves with the items and prefixes. `prefixes` contains references to sub-folders and `items` contains references to objects in this folder. `nextPageToken` can be used to get the rest of the results. ### listAll(ref) {:#listall_30df0b2} List all items (files) and prefixes (folders) under this storage reference. This is a helper method for calling list() repeatedly until there are no more results. The default pagination size is 1000. Note: The results may not be consistent if objects are changed while this operation is running. Warning: `listAll` may potentially consume too many resources if there are too many results. Signature: ```typescript export declare function listAll(ref: StorageReference): Promise; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | [StorageReference](./storage.storagereference.md#storagereference_interface) to get list from. | Returns: Promise<[ListResult](./storage.listresult.md#listresult_interface)> A `Promise` that resolves with all the items and prefixes under the current storage reference. `prefixes` contains references to sub-directories and `items` contains references to objects in this folder. `nextPageToken` is never returned. ### updateMetadata(ref, metadata) {:#updatemetadata_a634608} Updates the metadata for this object. Signature: ```typescript export declare function updateMetadata(ref: StorageReference, metadata: SettableMetadata): Promise; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | [StorageReference](./storage.storagereference.md#storagereference_interface) to update metadata for. | | metadata | [SettableMetadata](./storage.settablemetadata.md#settablemetadata_interface) | The new metadata for the object. Only values that have been explicitly set will be changed. Explicitly setting a value to null will remove the metadata. | Returns: Promise<[FullMetadata](./storage.fullmetadata.md#fullmetadata_interface)> A `Promise` that resolves with the new metadata for this object. ### uploadBytes(ref, data, metadata) {:#uploadbytes_02686b1} Uploads data to this object's location. The upload is not resumable. Signature: ```typescript export declare function uploadBytes(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): Promise; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | [StorageReference](./storage.storagereference.md#storagereference_interface) where data should be uploaded. | | data | Blob \| Uint8Array \| ArrayBuffer | The data to upload. | | metadata | [UploadMetadata](./storage.uploadmetadata.md#uploadmetadata_interface) | Metadata for the data to upload. | Returns: Promise<[UploadResult](./storage.uploadresult.md#uploadresult_interface)> A Promise containing an UploadResult ### uploadBytesResumable(ref, data, metadata) {:#uploadbytesresumable_02686b1} Uploads data to this object's location. The upload can be paused and resumed, and exposes progress updates. Signature: ```typescript export declare function uploadBytesResumable(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): UploadTask; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | [StorageReference](./storage.storagereference.md#storagereference_interface) where data should be uploaded. | | data | Blob \| Uint8Array \| ArrayBuffer | The data to upload. | | metadata | [UploadMetadata](./storage.uploadmetadata.md#uploadmetadata_interface) | Metadata for the data to upload. | Returns: [UploadTask](./storage.uploadtask.md#uploadtask_interface) An UploadTask ### uploadString(ref, value, format, metadata) {:#uploadstring_277829d} Uploads a string to this object's location. The upload is not resumable. Signature: ```typescript export declare function uploadString(ref: StorageReference, value: string, format?: StringFormat, metadata?: UploadMetadata): Promise; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | ref | [StorageReference](./storage.storagereference.md#storagereference_interface) | [StorageReference](./storage.storagereference.md#storagereference_interface) where string should be uploaded. | | value | string | The string to upload. | | format | [StringFormat](./storage.md#stringformat) | The format of the string to upload. | | metadata | [UploadMetadata](./storage.uploadmetadata.md#uploadmetadata_interface) | Metadata for the string to upload. | Returns: Promise<[UploadResult](./storage.uploadresult.md#uploadresult_interface)> A Promise containing an UploadResult ## function(storageOrRef, ...) ### ref(storageOrRef, path) {:#ref_41be95d} Returns a [StorageReference](./storage.storagereference.md#storagereference_interface) for the given path in the default bucket. Signature: ```typescript export declare function ref(storageOrRef: FirebaseStorage | StorageReference, path?: string): StorageReference; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | storageOrRef | [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) \| [StorageReference](./storage.storagereference.md#storagereference_interface) | [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) or [StorageReference](./storage.storagereference.md#storagereference_interface). | | path | string | | Returns: [StorageReference](./storage.storagereference.md#storagereference_interface) ## StringFormat An enumeration of the possible string formats for upload. Signature: ```typescript StringFormat: { readonly RAW: "raw"; readonly BASE64: "base64"; readonly BASE64URL: "base64url"; readonly DATA_URL: "data_url"; } ``` ## StringFormat An enumeration of the possible string formats for upload. Signature: ```typescript export type StringFormat = (typeof StringFormat)[keyof typeof StringFormat]; ``` ## TaskEvent An event that is triggered on a task. Signature: ```typescript export type TaskEvent = 'state_changed'; ``` ## TaskState Represents the current state of a running upload. Signature: ```typescript export type TaskState = 'running' | 'paused' | 'success' | 'canceled' | 'error'; ``` ## StorageErrorCode Error codes that can be attached to `StorageError` objects. Signature: ```typescript export declare enum StorageErrorCode ``` ## Enumeration Members | Member | Value | Description | | --- | --- | --- | | APP\_DELETED | "app-deleted" | | | BUCKET\_NOT\_FOUND | "bucket-not-found" | | | CANCELED | "canceled" | | | CANNOT\_SLICE\_BLOB | "cannot-slice-blob" | | | INTERNAL\_ERROR | "internal-error" | | | INVALID\_ARGUMENT | "invalid-argument" | | | INVALID\_ARGUMENT\_COUNT | "invalid-argument-count" | | | INVALID\_CHECKSUM | "invalid-checksum" | | | INVALID\_DEFAULT\_BUCKET | "invalid-default-bucket" | | | INVALID\_EVENT\_NAME | "invalid-event-name" | | | INVALID\_FORMAT | "invalid-format" | | | INVALID\_ROOT\_OPERATION | "invalid-root-operation" | | | INVALID\_URL | "invalid-url" | | | NO\_DEFAULT\_BUCKET | "no-default-bucket" | | | NO\_DOWNLOAD\_URL | "no-download-url" | | | OBJECT\_NOT\_FOUND | "object-not-found" | | | PROJECT\_NOT\_FOUND | "project-not-found" | | | QUOTA\_EXCEEDED | "quota-exceeded" | | | RETRY\_LIMIT\_EXCEEDED | "retry-limit-exceeded" | | | SERVER\_FILE\_WRONG\_SIZE | "server-file-wrong-size" | | | UNAUTHENTICATED | "unauthenticated" | | | UNAUTHORIZED | "unauthorized" | | | UNAUTHORIZED\_APP | "unauthorized-app" | | | UNKNOWN | "unknown" | | | UNSUPPORTED\_ENVIRONMENT | "unsupported-environment" | |