storage-public.d.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /**
  2. * Cloud Storage for Firebase
  3. *
  4. * @packageDocumentation
  5. */
  6. /// <reference types="node" />
  7. import { CompleteFn , EmulatorMockTokenOptions , FirebaseError , NextFn , Subscribe , Unsubscribe } from '@firebase/util';
  8. import { FirebaseApp } from '@firebase/app';
  9. /**
  10. * Modify this {@link FirebaseStorage} instance to communicate with the Cloud Storage emulator.
  11. *
  12. * @param storage - The {@link FirebaseStorage} instance
  13. * @param host - The emulator host (ex: localhost)
  14. * @param port - The emulator port (ex: 5001)
  15. * @param options - Emulator options. `options.mockUserToken` is the mock auth
  16. * token to use for unit testing Security Rules.
  17. * @public
  18. */
  19. export declare function connectStorageEmulator(storage: FirebaseStorage, host: string, port: number, options?: {
  20. mockUserToken?: EmulatorMockTokenOptions | string;
  21. }): void;
  22. /* Excluded from this release type: _dataFromString */
  23. /**
  24. * Deletes the object at this location.
  25. * @public
  26. * @param ref - {@link StorageReference} for object to delete.
  27. * @returns A `Promise` that resolves if the deletion succeeds.
  28. */
  29. export declare function deleteObject(ref: StorageReference): Promise<void>;
  30. export { EmulatorMockTokenOptions };
  31. /* Excluded from this release type: _FbsBlob */
  32. /* Excluded from this release type: _FirebaseService */
  33. /**
  34. * A Firebase Storage instance.
  35. * @public
  36. */
  37. export declare interface FirebaseStorage {
  38. /**
  39. * The {@link @firebase/app#FirebaseApp} associated with this `FirebaseStorage` instance.
  40. */
  41. readonly app: FirebaseApp;
  42. /**
  43. * The maximum time to retry uploads in milliseconds.
  44. */
  45. maxUploadRetryTime: number;
  46. /**
  47. * The maximum time to retry operations other than uploads or downloads in
  48. * milliseconds.
  49. */
  50. maxOperationRetryTime: number;
  51. }
  52. /* Excluded from this release type: _FirebaseStorageImpl */
  53. /**
  54. * The full set of object metadata, including read-only properties.
  55. * @public
  56. */
  57. export declare interface FullMetadata extends UploadMetadata {
  58. /**
  59. * The bucket this object is contained in.
  60. */
  61. bucket: string;
  62. /**
  63. * The full path of this object.
  64. */
  65. fullPath: string;
  66. /**
  67. * The object's generation.
  68. * {@link https://cloud.google.com/storage/docs/metadata#generation-number}
  69. */
  70. generation: string;
  71. /**
  72. * The object's metageneration.
  73. * {@link https://cloud.google.com/storage/docs/metadata#generation-number}
  74. */
  75. metageneration: string;
  76. /**
  77. * The short name of this object, which is the last component of the full path.
  78. * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
  79. */
  80. name: string;
  81. /**
  82. * The size of this object, in bytes.
  83. */
  84. size: number;
  85. /**
  86. * A date string representing when this object was created.
  87. */
  88. timeCreated: string;
  89. /**
  90. * A date string representing when this object was last updated.
  91. */
  92. updated: string;
  93. /**
  94. * Tokens to allow access to the downloatd URL.
  95. */
  96. downloadTokens: string[] | undefined;
  97. /**
  98. * `StorageReference` associated with this upload.
  99. */
  100. ref?: StorageReference | undefined;
  101. }
  102. /**
  103. * Downloads the data at the object's location. Returns an error if the object
  104. * is not found.
  105. *
  106. * To use this functionality, you have to whitelist your app's origin in your
  107. * Cloud Storage bucket. See also
  108. * https://cloud.google.com/storage/docs/configuring-cors
  109. *
  110. * This API is not available in Node.
  111. *
  112. * @public
  113. * @param ref - StorageReference where data should be downloaded.
  114. * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
  115. * retrieve.
  116. * @returns A Promise that resolves with a Blob containing the object's bytes
  117. */
  118. export declare function getBlob(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<Blob>;
  119. /**
  120. * Downloads the data at the object's location. Returns an error if the object
  121. * is not found.
  122. *
  123. * To use this functionality, you have to whitelist your app's origin in your
  124. * Cloud Storage bucket. See also
  125. * https://cloud.google.com/storage/docs/configuring-cors
  126. *
  127. * @public
  128. * @param ref - StorageReference where data should be downloaded.
  129. * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
  130. * retrieve.
  131. * @returns A Promise containing the object's bytes
  132. */
  133. export declare function getBytes(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<ArrayBuffer>;
  134. /* Excluded from this release type: _getChild */
  135. /**
  136. * Returns the download URL for the given {@link StorageReference}.
  137. * @public
  138. * @param ref - {@link StorageReference} to get the download URL for.
  139. * @returns A `Promise` that resolves with the download
  140. * URL for this object.
  141. */
  142. export declare function getDownloadURL(ref: StorageReference): Promise<string>;
  143. /**
  144. * A `Promise` that resolves with the metadata for this object. If this
  145. * object doesn't exist or metadata cannot be retreived, the promise is
  146. * rejected.
  147. * @public
  148. * @param ref - {@link StorageReference} to get metadata from.
  149. */
  150. export declare function getMetadata(ref: StorageReference): Promise<FullMetadata>;
  151. /**
  152. * Gets a {@link FirebaseStorage} instance for the given Firebase app.
  153. * @public
  154. * @param app - Firebase app to get {@link FirebaseStorage} instance for.
  155. * @param bucketUrl - The gs:// url to your Firebase Storage Bucket.
  156. * If not passed, uses the app's default Storage Bucket.
  157. * @returns A {@link FirebaseStorage} instance.
  158. */
  159. export declare function getStorage(app?: FirebaseApp, bucketUrl?: string): FirebaseStorage;
  160. /**
  161. * Downloads the data at the object's location. Raises an error event if the
  162. * object is not found.
  163. *
  164. * This API is only available in Node.
  165. *
  166. * @public
  167. * @param ref - StorageReference where data should be downloaded.
  168. * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
  169. * retrieve.
  170. * @returns A stream with the object's data as bytes
  171. */
  172. export declare function getStream(ref: StorageReference, maxDownloadSizeBytes?: number): NodeJS.ReadableStream;
  173. /* Excluded from this release type: _invalidArgument */
  174. /* Excluded from this release type: _invalidRootOperation */
  175. /**
  176. * List items (files) and prefixes (folders) under this storage reference.
  177. *
  178. * List API is only available for Firebase Rules Version 2.
  179. *
  180. * GCS is a key-blob store. Firebase Storage imposes the semantic of '/'
  181. * delimited folder structure.
  182. * Refer to GCS's List API if you want to learn more.
  183. *
  184. * To adhere to Firebase Rules's Semantics, Firebase Storage does not
  185. * support objects whose paths end with "/" or contain two consecutive
  186. * "/"s. Firebase Storage List API will filter these unsupported objects.
  187. * list() may fail if there are too many unsupported objects in the bucket.
  188. * @public
  189. *
  190. * @param ref - {@link StorageReference} to get list from.
  191. * @param options - See {@link ListOptions} for details.
  192. * @returns A `Promise` that resolves with the items and prefixes.
  193. * `prefixes` contains references to sub-folders and `items`
  194. * contains references to objects in this folder. `nextPageToken`
  195. * can be used to get the rest of the results.
  196. */
  197. export declare function list(ref: StorageReference, options?: ListOptions): Promise<ListResult>;
  198. /**
  199. * List all items (files) and prefixes (folders) under this storage reference.
  200. *
  201. * This is a helper method for calling list() repeatedly until there are
  202. * no more results. The default pagination size is 1000.
  203. *
  204. * Note: The results may not be consistent if objects are changed while this
  205. * operation is running.
  206. *
  207. * Warning: `listAll` may potentially consume too many resources if there are
  208. * too many results.
  209. * @public
  210. * @param ref - {@link StorageReference} to get list from.
  211. *
  212. * @returns A `Promise` that resolves with all the items and prefixes under
  213. * the current storage reference. `prefixes` contains references to
  214. * sub-directories and `items` contains references to objects in this
  215. * folder. `nextPageToken` is never returned.
  216. */
  217. export declare function listAll(ref: StorageReference): Promise<ListResult>;
  218. /**
  219. * The options `list()` accepts.
  220. * @public
  221. */
  222. export declare interface ListOptions {
  223. /**
  224. * If set, limits the total number of `prefixes` and `items` to return.
  225. * The default and maximum maxResults is 1000.
  226. */
  227. maxResults?: number | null;
  228. /**
  229. * The `nextPageToken` from a previous call to `list()`. If provided,
  230. * listing is resumed from the previous position.
  231. */
  232. pageToken?: string | null;
  233. }
  234. /**
  235. * Result returned by list().
  236. * @public
  237. */
  238. export declare interface ListResult {
  239. /**
  240. * References to prefixes (sub-folders). You can call list() on them to
  241. * get its contents.
  242. *
  243. * Folders are implicit based on '/' in the object paths.
  244. * For example, if a bucket has two objects '/a/b/1' and '/a/b/2', list('/a')
  245. * will return '/a/b' as a prefix.
  246. */
  247. prefixes: StorageReference[];
  248. /**
  249. * Objects in this directory.
  250. * You can call getMetadata() and getDownloadUrl() on them.
  251. */
  252. items: StorageReference[];
  253. /**
  254. * If set, there might be more results for this list. Use this token to resume the list.
  255. */
  256. nextPageToken?: string;
  257. }
  258. /**
  259. * Returns a {@link StorageReference} for the given url.
  260. * @param storage - {@link FirebaseStorage} instance.
  261. * @param url - URL. If empty, returns root reference.
  262. * @public
  263. */
  264. export declare function ref(storage: FirebaseStorage, url?: string): StorageReference;
  265. /**
  266. * Returns a {@link StorageReference} for the given path in the
  267. * default bucket.
  268. * @param storageOrRef - {@link FirebaseStorage} or {@link StorageReference}.
  269. * @param pathOrUrlStorage - path. If empty, returns root reference (if {@link FirebaseStorage}
  270. * instance provided) or returns same reference (if {@link StorageReference} provided).
  271. * @public
  272. */
  273. export declare function ref(storageOrRef: FirebaseStorage | StorageReference, path?: string): StorageReference;
  274. /**
  275. * Object metadata that can be set at any time.
  276. * @public
  277. */
  278. export declare interface SettableMetadata {
  279. /**
  280. * Served as the 'Cache-Control' header on object download.
  281. */
  282. cacheControl?: string | undefined;
  283. /**
  284. * Served as the 'Content-Disposition' header on object download.
  285. */
  286. contentDisposition?: string | undefined;
  287. /**
  288. * Served as the 'Content-Encoding' header on object download.
  289. */
  290. contentEncoding?: string | undefined;
  291. /**
  292. * Served as the 'Content-Language' header on object download.
  293. */
  294. contentLanguage?: string | undefined;
  295. /**
  296. * Served as the 'Content-Type' header on object download.
  297. */
  298. contentType?: string | undefined;
  299. /**
  300. * Additional user-defined custom metadata.
  301. */
  302. customMetadata?: {
  303. [key: string]: string;
  304. } | undefined;
  305. }
  306. /**
  307. * An error returned by the Firebase Storage SDK.
  308. * @public
  309. */
  310. export declare class StorageError extends FirebaseError {
  311. private status_;
  312. /**
  313. * Stores custom error data unique to the `StorageError`.
  314. */
  315. customData: {
  316. serverResponse: string | null;
  317. };
  318. /**
  319. * @param code - A `StorageErrorCode` string to be prefixed with 'storage/' and
  320. * added to the end of the message.
  321. * @param message - Error message.
  322. * @param status_ - Corresponding HTTP Status Code
  323. */
  324. constructor(code: StorageErrorCode, message: string, status_?: number);
  325. get status(): number;
  326. set status(status: number);
  327. /**
  328. * Optional response message that was added by the server.
  329. */
  330. get serverResponse(): null | string;
  331. set serverResponse(serverResponse: string | null);
  332. }
  333. /**
  334. * @public
  335. * Error codes that can be attached to `StorageError` objects.
  336. */
  337. export declare enum StorageErrorCode {
  338. UNKNOWN = "unknown",
  339. OBJECT_NOT_FOUND = "object-not-found",
  340. BUCKET_NOT_FOUND = "bucket-not-found",
  341. PROJECT_NOT_FOUND = "project-not-found",
  342. QUOTA_EXCEEDED = "quota-exceeded",
  343. UNAUTHENTICATED = "unauthenticated",
  344. UNAUTHORIZED = "unauthorized",
  345. UNAUTHORIZED_APP = "unauthorized-app",
  346. RETRY_LIMIT_EXCEEDED = "retry-limit-exceeded",
  347. INVALID_CHECKSUM = "invalid-checksum",
  348. CANCELED = "canceled",
  349. INVALID_EVENT_NAME = "invalid-event-name",
  350. INVALID_URL = "invalid-url",
  351. INVALID_DEFAULT_BUCKET = "invalid-default-bucket",
  352. NO_DEFAULT_BUCKET = "no-default-bucket",
  353. CANNOT_SLICE_BLOB = "cannot-slice-blob",
  354. SERVER_FILE_WRONG_SIZE = "server-file-wrong-size",
  355. NO_DOWNLOAD_URL = "no-download-url",
  356. INVALID_ARGUMENT = "invalid-argument",
  357. INVALID_ARGUMENT_COUNT = "invalid-argument-count",
  358. APP_DELETED = "app-deleted",
  359. INVALID_ROOT_OPERATION = "invalid-root-operation",
  360. INVALID_FORMAT = "invalid-format",
  361. INTERNAL_ERROR = "internal-error",
  362. UNSUPPORTED_ENVIRONMENT = "unsupported-environment"
  363. }
  364. /**
  365. * A stream observer for Firebase Storage.
  366. * @public
  367. */
  368. export declare interface StorageObserver<T> {
  369. next?: NextFn<T> | null;
  370. error?: (error: StorageError) => void | null;
  371. complete?: CompleteFn | null;
  372. }
  373. /**
  374. * Represents a reference to a Google Cloud Storage object. Developers can
  375. * upload, download, and delete objects, as well as get/set object metadata.
  376. * @public
  377. */
  378. export declare interface StorageReference {
  379. /**
  380. * Returns a gs:// URL for this object in the form
  381. * `gs://<bucket>/<path>/<to>/<object>`
  382. * @returns The gs:// URL.
  383. */
  384. toString(): string;
  385. /**
  386. * A reference to the root of this object's bucket.
  387. */
  388. root: StorageReference;
  389. /**
  390. * The name of the bucket containing this reference's object.
  391. */
  392. bucket: string;
  393. /**
  394. * The full path of this object.
  395. */
  396. fullPath: string;
  397. /**
  398. * The short name of this object, which is the last component of the full path.
  399. * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
  400. */
  401. name: string;
  402. /**
  403. * The {@link FirebaseStorage} instance associated with this reference.
  404. */
  405. storage: FirebaseStorage;
  406. /**
  407. * A reference pointing to the parent location of this reference, or null if
  408. * this reference is the root.
  409. */
  410. parent: StorageReference | null;
  411. }
  412. /**
  413. * @license
  414. * Copyright 2017 Google LLC
  415. *
  416. * Licensed under the Apache License, Version 2.0 (the "License");
  417. * you may not use this file except in compliance with the License.
  418. * You may obtain a copy of the License at
  419. *
  420. * http://www.apache.org/licenses/LICENSE-2.0
  421. *
  422. * Unless required by applicable law or agreed to in writing, software
  423. * distributed under the License is distributed on an "AS IS" BASIS,
  424. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  425. * See the License for the specific language governing permissions and
  426. * limitations under the License.
  427. */
  428. /**
  429. * An enumeration of the possible string formats for upload.
  430. * @public
  431. */
  432. export declare type StringFormat = typeof StringFormat[keyof typeof StringFormat];
  433. /**
  434. * An enumeration of the possible string formats for upload.
  435. * @public
  436. */
  437. export declare const StringFormat: {
  438. /**
  439. * Indicates the string should be interpreted "raw", that is, as normal text.
  440. * The string will be interpreted as UTF-16, then uploaded as a UTF-8 byte
  441. * sequence.
  442. * Example: The string 'Hello! \\ud83d\\ude0a' becomes the byte sequence
  443. * 48 65 6c 6c 6f 21 20 f0 9f 98 8a
  444. */
  445. readonly RAW: "raw";
  446. /**
  447. * Indicates the string should be interpreted as base64-encoded data.
  448. * Padding characters (trailing '='s) are optional.
  449. * Example: The string 'rWmO++E6t7/rlw==' becomes the byte sequence
  450. * ad 69 8e fb e1 3a b7 bf eb 97
  451. */
  452. readonly BASE64: "base64";
  453. /**
  454. * Indicates the string should be interpreted as base64url-encoded data.
  455. * Padding characters (trailing '='s) are optional.
  456. * Example: The string 'rWmO--E6t7_rlw==' becomes the byte sequence
  457. * ad 69 8e fb e1 3a b7 bf eb 97
  458. */
  459. readonly BASE64URL: "base64url";
  460. /**
  461. * Indicates the string is a data URL, such as one obtained from
  462. * canvas.toDataURL().
  463. * Example: the string 'data:application/octet-stream;base64,aaaa'
  464. * becomes the byte sequence
  465. * 69 a6 9a
  466. * (the content-type "application/octet-stream" is also applied, but can
  467. * be overridden in the metadata object).
  468. */
  469. readonly DATA_URL: "data_url";
  470. };
  471. /**
  472. * An event that is triggered on a task.
  473. * @public
  474. */
  475. export declare type TaskEvent = 'state_changed';
  476. /* Excluded from this release type: _TaskEvent */
  477. /**
  478. * Represents the current state of a running upload.
  479. * @public
  480. */
  481. export declare type TaskState = 'running' | 'paused' | 'success' | 'canceled' | 'error';
  482. /**
  483. * Updates the metadata for this object.
  484. * @public
  485. * @param ref - {@link StorageReference} to update metadata for.
  486. * @param metadata - The new metadata for the object.
  487. * Only values that have been explicitly set will be changed. Explicitly
  488. * setting a value to null will remove the metadata.
  489. * @returns A `Promise` that resolves with the new metadata for this object.
  490. */
  491. export declare function updateMetadata(ref: StorageReference, metadata: SettableMetadata): Promise<FullMetadata>;
  492. /**
  493. * Uploads data to this object's location.
  494. * The upload is not resumable.
  495. * @public
  496. * @param ref - {@link StorageReference} where data should be uploaded.
  497. * @param data - The data to upload.
  498. * @param metadata - Metadata for the data to upload.
  499. * @returns A Promise containing an UploadResult
  500. */
  501. export declare function uploadBytes(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): Promise<UploadResult>;
  502. /**
  503. * Uploads data to this object's location.
  504. * The upload can be paused and resumed, and exposes progress updates.
  505. * @public
  506. * @param ref - {@link StorageReference} where data should be uploaded.
  507. * @param data - The data to upload.
  508. * @param metadata - Metadata for the data to upload.
  509. * @returns An UploadTask
  510. */
  511. export declare function uploadBytesResumable(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): UploadTask;
  512. /**
  513. * Object metadata that can be set at upload.
  514. * @public
  515. */
  516. export declare interface UploadMetadata extends SettableMetadata {
  517. /**
  518. * A Base64-encoded MD5 hash of the object being uploaded.
  519. */
  520. md5Hash?: string | undefined;
  521. }
  522. /**
  523. * Result returned from a non-resumable upload.
  524. * @public
  525. */
  526. export declare interface UploadResult {
  527. /**
  528. * Contains the metadata sent back from the server.
  529. */
  530. readonly metadata: FullMetadata;
  531. /**
  532. * The reference that spawned this upload.
  533. */
  534. readonly ref: StorageReference;
  535. }
  536. /**
  537. * Uploads a string to this object's location.
  538. * The upload is not resumable.
  539. * @public
  540. * @param ref - {@link StorageReference} where string should be uploaded.
  541. * @param value - The string to upload.
  542. * @param format - The format of the string to upload.
  543. * @param metadata - Metadata for the string to upload.
  544. * @returns A Promise containing an UploadResult
  545. */
  546. export declare function uploadString(ref: StorageReference, value: string, format?: StringFormat, metadata?: UploadMetadata): Promise<UploadResult>;
  547. /**
  548. * Represents the process of uploading an object. Allows you to monitor and
  549. * manage the upload.
  550. * @public
  551. */
  552. export declare interface UploadTask {
  553. /**
  554. * Cancels a running task. Has no effect on a complete or failed task.
  555. * @returns True if the cancel had an effect.
  556. */
  557. cancel(): boolean;
  558. /**
  559. * Equivalent to calling `then(null, onRejected)`.
  560. */
  561. catch(onRejected: (error: StorageError) => unknown): Promise<unknown>;
  562. /**
  563. * Listens for events on this task.
  564. *
  565. * Events have three callback functions (referred to as `next`, `error`, and
  566. * `complete`).
  567. *
  568. * If only the event is passed, a function that can be used to register the
  569. * callbacks is returned. Otherwise, the callbacks are passed after the event.
  570. *
  571. * Callbacks can be passed either as three separate arguments <em>or</em> as the
  572. * `next`, `error`, and `complete` properties of an object. Any of the three
  573. * callbacks is optional, as long as at least one is specified. In addition,
  574. * when you add your callbacks, you get a function back. You can call this
  575. * function to unregister the associated callbacks.
  576. *
  577. * @example **Pass callbacks separately or in an object.**
  578. * ```javascript
  579. * var next = function(snapshot) {};
  580. * var error = function(error) {};
  581. * var complete = function() {};
  582. *
  583. * // The first example.
  584. * uploadTask.on(
  585. * firebase.storage.TaskEvent.STATE_CHANGED,
  586. * next,
  587. * error,
  588. * complete);
  589. *
  590. * // This is equivalent to the first example.
  591. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
  592. * 'next': next,
  593. * 'error': error,
  594. * 'complete': complete
  595. * });
  596. *
  597. * // This is equivalent to the first example.
  598. * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  599. * subscribe(next, error, complete);
  600. *
  601. * // This is equivalent to the first example.
  602. * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  603. * subscribe({
  604. * 'next': next,
  605. * 'error': error,
  606. * 'complete': complete
  607. * });
  608. * ```
  609. *
  610. * @example **Any callback is optional.**
  611. * ```javascript
  612. * // Just listening for completion, this is legal.
  613. * uploadTask.on(
  614. * firebase.storage.TaskEvent.STATE_CHANGED,
  615. * null,
  616. * null,
  617. * function() {
  618. * console.log('upload complete!');
  619. * });
  620. *
  621. * // Just listening for progress/state changes, this is legal.
  622. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, function(snapshot) {
  623. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  624. * console.log(percent + "% done");
  625. * });
  626. *
  627. * // This is also legal.
  628. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
  629. * 'complete': function() {
  630. * console.log('upload complete!');
  631. * }
  632. * });
  633. * ```
  634. *
  635. * @example **Use the returned function to remove callbacks.**
  636. * ```javascript
  637. * var unsubscribe = uploadTask.on(
  638. * firebase.storage.TaskEvent.STATE_CHANGED,
  639. * function(snapshot) {
  640. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  641. * console.log(percent + "% done");
  642. * // Stop after receiving one update.
  643. * unsubscribe();
  644. * });
  645. *
  646. * // This code is equivalent to the above.
  647. * var handle = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  648. * unsubscribe = handle(function(snapshot) {
  649. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  650. * console.log(percent + "% done");
  651. * // Stop after receiving one update.
  652. * unsubscribe();
  653. * });
  654. * ```
  655. *
  656. * @param event - The type of event to listen for.
  657. * @param nextOrObserver -
  658. * The `next` function, which gets called for each item in
  659. * the event stream, or an observer object with some or all of these three
  660. * properties (`next`, `error`, `complete`).
  661. * @param error - A function that gets called with a `StorageError`
  662. * if the event stream ends due to an error.
  663. * @param completed - A function that gets called if the
  664. * event stream ends normally.
  665. * @returns
  666. * If only the event argument is passed, returns a function you can use to
  667. * add callbacks (see the examples above). If more than just the event
  668. * argument is passed, returns a function you can call to unregister the
  669. * callbacks.
  670. */
  671. on(event: TaskEvent, nextOrObserver?: StorageObserver<UploadTaskSnapshot> | null | ((snapshot: UploadTaskSnapshot) => unknown), error?: ((a: StorageError) => unknown) | null, complete?: Unsubscribe | null): Unsubscribe | Subscribe<UploadTaskSnapshot>;
  672. /**
  673. * Pauses a currently running task. Has no effect on a paused or failed task.
  674. * @returns True if the operation took effect, false if ignored.
  675. */
  676. pause(): boolean;
  677. /**
  678. * Resumes a paused task. Has no effect on a currently running or failed task.
  679. * @returns True if the operation took effect, false if ignored.
  680. */
  681. resume(): boolean;
  682. /**
  683. * A snapshot of the current task state.
  684. */
  685. snapshot: UploadTaskSnapshot;
  686. /**
  687. * This object behaves like a Promise, and resolves with its snapshot data
  688. * when the upload completes.
  689. * @param onFulfilled - The fulfillment callback. Promise chaining works as normal.
  690. * @param onRejected - The rejection callback.
  691. */
  692. then(onFulfilled?: ((snapshot: UploadTaskSnapshot) => unknown) | null, onRejected?: ((error: StorageError) => unknown) | null): Promise<unknown>;
  693. }
  694. /* Excluded from this release type: _UploadTask */
  695. /**
  696. * Holds data about the current state of the upload task.
  697. * @public
  698. */
  699. export declare interface UploadTaskSnapshot {
  700. /**
  701. * The number of bytes that have been successfully uploaded so far.
  702. */
  703. bytesTransferred: number;
  704. /**
  705. * Before the upload completes, contains the metadata sent to the server.
  706. * After the upload completes, contains the metadata sent back from the server.
  707. */
  708. metadata: FullMetadata;
  709. /**
  710. * The reference that spawned this snapshot's upload task.
  711. */
  712. ref: StorageReference;
  713. /**
  714. * The current state of the task.
  715. */
  716. state: TaskState;
  717. /**
  718. * The task of which this is a snapshot.
  719. */
  720. task: UploadTask;
  721. /**
  722. * The total number of bytes to be uploaded.
  723. */
  724. totalBytes: number;
  725. }
  726. export {};