/**
* Cloud Storage for Firebase
*
* @packageDocumentation
*/
///
import { CompleteFn , EmulatorMockTokenOptions , FirebaseError , NextFn , Subscribe , Unsubscribe } from '@firebase/util';
import { FirebaseApp } from '@firebase/app';
/**
* Modify this {@link FirebaseStorage} instance to communicate with the Cloud Storage emulator.
*
* @param storage - The {@link FirebaseStorage} instance
* @param host - The emulator host (ex: localhost)
* @param port - The emulator port (ex: 5001)
* @param options - Emulator options. `options.mockUserToken` is the mock auth
* token to use for unit testing Security Rules.
* @public
*/
export declare function connectStorageEmulator(storage: FirebaseStorage, host: string, port: number, options?: {
mockUserToken?: EmulatorMockTokenOptions | string;
}): void;
/* Excluded from this release type: _dataFromString */
/**
* Deletes the object at this location.
* @public
* @param ref - {@link StorageReference} for object to delete.
* @returns A `Promise` that resolves if the deletion succeeds.
*/
export declare function deleteObject(ref: StorageReference): Promise;
export { EmulatorMockTokenOptions };
/* Excluded from this release type: _FbsBlob */
/* Excluded from this release type: _FirebaseService */
/**
* A Firebase Storage instance.
* @public
*/
export declare interface FirebaseStorage {
/**
* The {@link @firebase/app#FirebaseApp} associated with this `FirebaseStorage` instance.
*/
readonly app: FirebaseApp;
/**
* The maximum time to retry uploads in milliseconds.
*/
maxUploadRetryTime: number;
/**
* The maximum time to retry operations other than uploads or downloads in
* milliseconds.
*/
maxOperationRetryTime: number;
}
/* Excluded from this release type: _FirebaseStorageImpl */
/**
* The full set of object metadata, including read-only properties.
* @public
*/
export declare interface FullMetadata extends UploadMetadata {
/**
* The bucket this object is contained in.
*/
bucket: string;
/**
* The full path of this object.
*/
fullPath: string;
/**
* The object's generation.
* {@link https://cloud.google.com/storage/docs/metadata#generation-number}
*/
generation: string;
/**
* The object's metageneration.
* {@link https://cloud.google.com/storage/docs/metadata#generation-number}
*/
metageneration: string;
/**
* The short name of this object, which is the last component of the full path.
* For example, if fullPath is 'full/path/image.png', name is 'image.png'.
*/
name: string;
/**
* The size of this object, in bytes.
*/
size: number;
/**
* A date string representing when this object was created.
*/
timeCreated: string;
/**
* A date string representing when this object was last updated.
*/
updated: string;
/**
* Tokens to allow access to the downloatd URL.
*/
downloadTokens: string[] | undefined;
/**
* `StorageReference` associated with this upload.
*/
ref?: StorageReference | undefined;
}
/**
* 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.
*
* @public
* @param ref - StorageReference where data should be downloaded.
* @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
* retrieve.
* @returns A Promise that resolves with a Blob containing the object's bytes
*/
export declare function getBlob(ref: StorageReference, maxDownloadSizeBytes?: number): Promise;
/**
* 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
*
* @public
* @param ref - StorageReference where data should be downloaded.
* @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
* retrieve.
* @returns A Promise containing the object's bytes
*/
export declare function getBytes(ref: StorageReference, maxDownloadSizeBytes?: number): Promise;
/* Excluded from this release type: _getChild */
/**
* Returns the download URL for the given {@link StorageReference}.
* @public
* @param ref - {@link StorageReference} to get the download URL for.
* @returns A `Promise` that resolves with the download
* URL for this object.
*/
export declare function getDownloadURL(ref: StorageReference): Promise;
/**
* A `Promise` that resolves with the metadata for this object. If this
* object doesn't exist or metadata cannot be retreived, the promise is
* rejected.
* @public
* @param ref - {@link StorageReference} to get metadata from.
*/
export declare function getMetadata(ref: StorageReference): Promise;
/**
* Gets a {@link FirebaseStorage} instance for the given Firebase app.
* @public
* @param app - Firebase app to get {@link FirebaseStorage} instance for.
* @param bucketUrl - The gs:// url to your Firebase Storage Bucket.
* If not passed, uses the app's default Storage Bucket.
* @returns A {@link FirebaseStorage} instance.
*/
export declare function getStorage(app?: FirebaseApp, bucketUrl?: string): FirebaseStorage;
/**
* 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.
*
* @public
* @param ref - StorageReference where data should be downloaded.
* @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
* retrieve.
* @returns A stream with the object's data as bytes
*/
export declare function getStream(ref: StorageReference, maxDownloadSizeBytes?: number): NodeJS.ReadableStream;
/* Excluded from this release type: _invalidArgument */
/* Excluded from this release type: _invalidRootOperation */
/**
* 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.
* @public
*
* @param ref - {@link StorageReference} to get list from.
* @param options - See {@link ListOptions} for details.
* @returns 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.
*/
export declare function list(ref: StorageReference, options?: ListOptions): Promise;
/**
* 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.
* @public
* @param ref - {@link StorageReference} to get list from.
*
* @returns 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.
*/
export declare function listAll(ref: StorageReference): Promise;
/**
* The options `list()` accepts.
* @public
*/
export declare interface ListOptions {
/**
* If set, limits the total number of `prefixes` and `items` to return.
* The default and maximum maxResults is 1000.
*/
maxResults?: number | null;
/**
* The `nextPageToken` from a previous call to `list()`. If provided,
* listing is resumed from the previous position.
*/
pageToken?: string | null;
}
/**
* Result returned by list().
* @public
*/
export declare interface ListResult {
/**
* References to prefixes (sub-folders). You can call list() on them to
* get its contents.
*
* Folders are implicit based on '/' in the object paths.
* For example, if a bucket has two objects '/a/b/1' and '/a/b/2', list('/a')
* will return '/a/b' as a prefix.
*/
prefixes: StorageReference[];
/**
* Objects in this directory.
* You can call getMetadata() and getDownloadUrl() on them.
*/
items: StorageReference[];
/**
* If set, there might be more results for this list. Use this token to resume the list.
*/
nextPageToken?: string;
}
/**
* Returns a {@link StorageReference} for the given url.
* @param storage - {@link FirebaseStorage} instance.
* @param url - URL. If empty, returns root reference.
* @public
*/
export declare function ref(storage: FirebaseStorage, url?: string): StorageReference;
/**
* Returns a {@link StorageReference} for the given path in the
* default bucket.
* @param storageOrRef - {@link FirebaseStorage} or {@link StorageReference}.
* @param pathOrUrlStorage - path. If empty, returns root reference (if {@link FirebaseStorage}
* instance provided) or returns same reference (if {@link StorageReference} provided).
* @public
*/
export declare function ref(storageOrRef: FirebaseStorage | StorageReference, path?: string): StorageReference;
/**
* Object metadata that can be set at any time.
* @public
*/
export declare interface SettableMetadata {
/**
* Served as the 'Cache-Control' header on object download.
*/
cacheControl?: string | undefined;
/**
* Served as the 'Content-Disposition' header on object download.
*/
contentDisposition?: string | undefined;
/**
* Served as the 'Content-Encoding' header on object download.
*/
contentEncoding?: string | undefined;
/**
* Served as the 'Content-Language' header on object download.
*/
contentLanguage?: string | undefined;
/**
* Served as the 'Content-Type' header on object download.
*/
contentType?: string | undefined;
/**
* Additional user-defined custom metadata.
*/
customMetadata?: {
[key: string]: string;
} | undefined;
}
/**
* An error returned by the Firebase Storage SDK.
* @public
*/
export declare class StorageError extends FirebaseError {
private status_;
/**
* Stores custom error data unique to the `StorageError`.
*/
customData: {
serverResponse: string | null;
};
/**
* @param code - A `StorageErrorCode` string to be prefixed with 'storage/' and
* added to the end of the message.
* @param message - Error message.
* @param status_ - Corresponding HTTP Status Code
*/
constructor(code: StorageErrorCode, message: string, status_?: number);
get status(): number;
set status(status: number);
/**
* Optional response message that was added by the server.
*/
get serverResponse(): null | string;
set serverResponse(serverResponse: string | null);
}
/**
* @public
* Error codes that can be attached to `StorageError` objects.
*/
export declare enum StorageErrorCode {
UNKNOWN = "unknown",
OBJECT_NOT_FOUND = "object-not-found",
BUCKET_NOT_FOUND = "bucket-not-found",
PROJECT_NOT_FOUND = "project-not-found",
QUOTA_EXCEEDED = "quota-exceeded",
UNAUTHENTICATED = "unauthenticated",
UNAUTHORIZED = "unauthorized",
UNAUTHORIZED_APP = "unauthorized-app",
RETRY_LIMIT_EXCEEDED = "retry-limit-exceeded",
INVALID_CHECKSUM = "invalid-checksum",
CANCELED = "canceled",
INVALID_EVENT_NAME = "invalid-event-name",
INVALID_URL = "invalid-url",
INVALID_DEFAULT_BUCKET = "invalid-default-bucket",
NO_DEFAULT_BUCKET = "no-default-bucket",
CANNOT_SLICE_BLOB = "cannot-slice-blob",
SERVER_FILE_WRONG_SIZE = "server-file-wrong-size",
NO_DOWNLOAD_URL = "no-download-url",
INVALID_ARGUMENT = "invalid-argument",
INVALID_ARGUMENT_COUNT = "invalid-argument-count",
APP_DELETED = "app-deleted",
INVALID_ROOT_OPERATION = "invalid-root-operation",
INVALID_FORMAT = "invalid-format",
INTERNAL_ERROR = "internal-error",
UNSUPPORTED_ENVIRONMENT = "unsupported-environment"
}
/**
* A stream observer for Firebase Storage.
* @public
*/
export declare interface StorageObserver {
next?: NextFn | null;
error?: (error: StorageError) => void | null;
complete?: CompleteFn | null;
}
/**
* Represents a reference to a Google Cloud Storage object. Developers can
* upload, download, and delete objects, as well as get/set object metadata.
* @public
*/
export declare interface StorageReference {
/**
* Returns a gs:// URL for this object in the form
* `gs://///