No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

storage-public.d.ts 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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 interface StorageError extends FirebaseError {
  311. /**
  312. * A server response message for the error, if applicable.
  313. */
  314. serverResponse: string | null;
  315. }
  316. /**
  317. * A stream observer for Firebase Storage.
  318. * @public
  319. */
  320. export declare interface StorageObserver<T> {
  321. next?: NextFn<T> | null;
  322. error?: (error: StorageError) => void | null;
  323. complete?: CompleteFn | null;
  324. }
  325. /**
  326. * Represents a reference to a Google Cloud Storage object. Developers can
  327. * upload, download, and delete objects, as well as get/set object metadata.
  328. * @public
  329. */
  330. export declare interface StorageReference {
  331. /**
  332. * Returns a gs:// URL for this object in the form
  333. * `gs://<bucket>/<path>/<to>/<object>`
  334. * @returns The gs:// URL.
  335. */
  336. toString(): string;
  337. /**
  338. * A reference to the root of this object's bucket.
  339. */
  340. root: StorageReference;
  341. /**
  342. * The name of the bucket containing this reference's object.
  343. */
  344. bucket: string;
  345. /**
  346. * The full path of this object.
  347. */
  348. fullPath: string;
  349. /**
  350. * The short name of this object, which is the last component of the full path.
  351. * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
  352. */
  353. name: string;
  354. /**
  355. * The {@link FirebaseStorage} instance associated with this reference.
  356. */
  357. storage: FirebaseStorage;
  358. /**
  359. * A reference pointing to the parent location of this reference, or null if
  360. * this reference is the root.
  361. */
  362. parent: StorageReference | null;
  363. }
  364. /**
  365. * @license
  366. * Copyright 2017 Google LLC
  367. *
  368. * Licensed under the Apache License, Version 2.0 (the "License");
  369. * you may not use this file except in compliance with the License.
  370. * You may obtain a copy of the License at
  371. *
  372. * http://www.apache.org/licenses/LICENSE-2.0
  373. *
  374. * Unless required by applicable law or agreed to in writing, software
  375. * distributed under the License is distributed on an "AS IS" BASIS,
  376. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  377. * See the License for the specific language governing permissions and
  378. * limitations under the License.
  379. */
  380. /**
  381. * An enumeration of the possible string formats for upload.
  382. * @public
  383. */
  384. export declare type StringFormat = typeof StringFormat[keyof typeof StringFormat];
  385. /**
  386. * An enumeration of the possible string formats for upload.
  387. * @public
  388. */
  389. export declare const StringFormat: {
  390. /**
  391. * Indicates the string should be interpreted "raw", that is, as normal text.
  392. * The string will be interpreted as UTF-16, then uploaded as a UTF-8 byte
  393. * sequence.
  394. * Example: The string 'Hello! \\ud83d\\ude0a' becomes the byte sequence
  395. * 48 65 6c 6c 6f 21 20 f0 9f 98 8a
  396. */
  397. readonly RAW: "raw";
  398. /**
  399. * Indicates the string should be interpreted as base64-encoded data.
  400. * Padding characters (trailing '='s) are optional.
  401. * Example: The string 'rWmO++E6t7/rlw==' becomes the byte sequence
  402. * ad 69 8e fb e1 3a b7 bf eb 97
  403. */
  404. readonly BASE64: "base64";
  405. /**
  406. * Indicates the string should be interpreted as base64url-encoded data.
  407. * Padding characters (trailing '='s) are optional.
  408. * Example: The string 'rWmO--E6t7_rlw==' becomes the byte sequence
  409. * ad 69 8e fb e1 3a b7 bf eb 97
  410. */
  411. readonly BASE64URL: "base64url";
  412. /**
  413. * Indicates the string is a data URL, such as one obtained from
  414. * canvas.toDataURL().
  415. * Example: the string 'data:application/octet-stream;base64,aaaa'
  416. * becomes the byte sequence
  417. * 69 a6 9a
  418. * (the content-type "application/octet-stream" is also applied, but can
  419. * be overridden in the metadata object).
  420. */
  421. readonly DATA_URL: "data_url";
  422. };
  423. /**
  424. * An event that is triggered on a task.
  425. * @public
  426. */
  427. export declare type TaskEvent = 'state_changed';
  428. /* Excluded from this release type: _TaskEvent */
  429. /**
  430. * Represents the current state of a running upload.
  431. * @public
  432. */
  433. export declare type TaskState = 'running' | 'paused' | 'success' | 'canceled' | 'error';
  434. /**
  435. * Updates the metadata for this object.
  436. * @public
  437. * @param ref - {@link StorageReference} to update metadata for.
  438. * @param metadata - The new metadata for the object.
  439. * Only values that have been explicitly set will be changed. Explicitly
  440. * setting a value to null will remove the metadata.
  441. * @returns A `Promise` that resolves with the new metadata for this object.
  442. */
  443. export declare function updateMetadata(ref: StorageReference, metadata: SettableMetadata): Promise<FullMetadata>;
  444. /**
  445. * Uploads data to this object's location.
  446. * The upload is not resumable.
  447. * @public
  448. * @param ref - {@link StorageReference} where data should be uploaded.
  449. * @param data - The data to upload.
  450. * @param metadata - Metadata for the data to upload.
  451. * @returns A Promise containing an UploadResult
  452. */
  453. export declare function uploadBytes(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): Promise<UploadResult>;
  454. /**
  455. * Uploads data to this object's location.
  456. * The upload can be paused and resumed, and exposes progress updates.
  457. * @public
  458. * @param ref - {@link StorageReference} where data should be uploaded.
  459. * @param data - The data to upload.
  460. * @param metadata - Metadata for the data to upload.
  461. * @returns An UploadTask
  462. */
  463. export declare function uploadBytesResumable(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): UploadTask;
  464. /**
  465. * Object metadata that can be set at upload.
  466. * @public
  467. */
  468. export declare interface UploadMetadata extends SettableMetadata {
  469. /**
  470. * A Base64-encoded MD5 hash of the object being uploaded.
  471. */
  472. md5Hash?: string | undefined;
  473. }
  474. /**
  475. * Result returned from a non-resumable upload.
  476. * @public
  477. */
  478. export declare interface UploadResult {
  479. /**
  480. * Contains the metadata sent back from the server.
  481. */
  482. readonly metadata: FullMetadata;
  483. /**
  484. * The reference that spawned this upload.
  485. */
  486. readonly ref: StorageReference;
  487. }
  488. /**
  489. * Uploads a string to this object's location.
  490. * The upload is not resumable.
  491. * @public
  492. * @param ref - {@link StorageReference} where string should be uploaded.
  493. * @param value - The string to upload.
  494. * @param format - The format of the string to upload.
  495. * @param metadata - Metadata for the string to upload.
  496. * @returns A Promise containing an UploadResult
  497. */
  498. export declare function uploadString(ref: StorageReference, value: string, format?: StringFormat, metadata?: UploadMetadata): Promise<UploadResult>;
  499. /**
  500. * Represents the process of uploading an object. Allows you to monitor and
  501. * manage the upload.
  502. * @public
  503. */
  504. export declare interface UploadTask {
  505. /**
  506. * Cancels a running task. Has no effect on a complete or failed task.
  507. * @returns True if the cancel had an effect.
  508. */
  509. cancel(): boolean;
  510. /**
  511. * Equivalent to calling `then(null, onRejected)`.
  512. */
  513. catch(onRejected: (error: StorageError) => unknown): Promise<unknown>;
  514. /**
  515. * Listens for events on this task.
  516. *
  517. * Events have three callback functions (referred to as `next`, `error`, and
  518. * `complete`).
  519. *
  520. * If only the event is passed, a function that can be used to register the
  521. * callbacks is returned. Otherwise, the callbacks are passed after the event.
  522. *
  523. * Callbacks can be passed either as three separate arguments <em>or</em> as the
  524. * `next`, `error`, and `complete` properties of an object. Any of the three
  525. * callbacks is optional, as long as at least one is specified. In addition,
  526. * when you add your callbacks, you get a function back. You can call this
  527. * function to unregister the associated callbacks.
  528. *
  529. * @example **Pass callbacks separately or in an object.**
  530. * ```javascript
  531. * var next = function(snapshot) {};
  532. * var error = function(error) {};
  533. * var complete = function() {};
  534. *
  535. * // The first example.
  536. * uploadTask.on(
  537. * firebase.storage.TaskEvent.STATE_CHANGED,
  538. * next,
  539. * error,
  540. * complete);
  541. *
  542. * // This is equivalent to the first example.
  543. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
  544. * 'next': next,
  545. * 'error': error,
  546. * 'complete': complete
  547. * });
  548. *
  549. * // This is equivalent to the first example.
  550. * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  551. * subscribe(next, error, complete);
  552. *
  553. * // This is equivalent to the first example.
  554. * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  555. * subscribe({
  556. * 'next': next,
  557. * 'error': error,
  558. * 'complete': complete
  559. * });
  560. * ```
  561. *
  562. * @example **Any callback is optional.**
  563. * ```javascript
  564. * // Just listening for completion, this is legal.
  565. * uploadTask.on(
  566. * firebase.storage.TaskEvent.STATE_CHANGED,
  567. * null,
  568. * null,
  569. * function() {
  570. * console.log('upload complete!');
  571. * });
  572. *
  573. * // Just listening for progress/state changes, this is legal.
  574. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, function(snapshot) {
  575. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  576. * console.log(percent + "% done");
  577. * });
  578. *
  579. * // This is also legal.
  580. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
  581. * 'complete': function() {
  582. * console.log('upload complete!');
  583. * }
  584. * });
  585. * ```
  586. *
  587. * @example **Use the returned function to remove callbacks.**
  588. * ```javascript
  589. * var unsubscribe = uploadTask.on(
  590. * firebase.storage.TaskEvent.STATE_CHANGED,
  591. * function(snapshot) {
  592. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  593. * console.log(percent + "% done");
  594. * // Stop after receiving one update.
  595. * unsubscribe();
  596. * });
  597. *
  598. * // This code is equivalent to the above.
  599. * var handle = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  600. * unsubscribe = handle(function(snapshot) {
  601. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  602. * console.log(percent + "% done");
  603. * // Stop after receiving one update.
  604. * unsubscribe();
  605. * });
  606. * ```
  607. *
  608. * @param event - The type of event to listen for.
  609. * @param nextOrObserver -
  610. * The `next` function, which gets called for each item in
  611. * the event stream, or an observer object with some or all of these three
  612. * properties (`next`, `error`, `complete`).
  613. * @param error - A function that gets called with a `StorageError`
  614. * if the event stream ends due to an error.
  615. * @param completed - A function that gets called if the
  616. * event stream ends normally.
  617. * @returns
  618. * If only the event argument is passed, returns a function you can use to
  619. * add callbacks (see the examples above). If more than just the event
  620. * argument is passed, returns a function you can call to unregister the
  621. * callbacks.
  622. */
  623. on(event: TaskEvent, nextOrObserver?: StorageObserver<UploadTaskSnapshot> | null | ((snapshot: UploadTaskSnapshot) => unknown), error?: ((a: StorageError) => unknown) | null, complete?: Unsubscribe | null): Unsubscribe | Subscribe<UploadTaskSnapshot>;
  624. /**
  625. * Pauses a currently running task. Has no effect on a paused or failed task.
  626. * @returns True if the operation took effect, false if ignored.
  627. */
  628. pause(): boolean;
  629. /**
  630. * Resumes a paused task. Has no effect on a currently running or failed task.
  631. * @returns True if the operation took effect, false if ignored.
  632. */
  633. resume(): boolean;
  634. /**
  635. * A snapshot of the current task state.
  636. */
  637. snapshot: UploadTaskSnapshot;
  638. /**
  639. * This object behaves like a Promise, and resolves with its snapshot data
  640. * when the upload completes.
  641. * @param onFulfilled - The fulfillment callback. Promise chaining works as normal.
  642. * @param onRejected - The rejection callback.
  643. */
  644. then(onFulfilled?: ((snapshot: UploadTaskSnapshot) => unknown) | null, onRejected?: ((error: StorageError) => unknown) | null): Promise<unknown>;
  645. }
  646. /* Excluded from this release type: _UploadTask */
  647. /**
  648. * Holds data about the current state of the upload task.
  649. * @public
  650. */
  651. export declare interface UploadTaskSnapshot {
  652. /**
  653. * The number of bytes that have been successfully uploaded so far.
  654. */
  655. bytesTransferred: number;
  656. /**
  657. * Before the upload completes, contains the metadata sent to the server.
  658. * After the upload completes, contains the metadata sent back from the server.
  659. */
  660. metadata: FullMetadata;
  661. /**
  662. * The reference that spawned this snapshot's upload task.
  663. */
  664. ref: StorageReference;
  665. /**
  666. * The current state of the task.
  667. */
  668. state: TaskState;
  669. /**
  670. * The task of which this is a snapshot.
  671. */
  672. task: UploadTask;
  673. /**
  674. * The total number of bytes to be uploaded.
  675. */
  676. totalBytes: number;
  677. }
  678. export {};