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.d.ts 46KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. /**
  2. * Cloud Storage for Firebase
  3. *
  4. * @packageDocumentation
  5. */
  6. /// <reference types="node" />
  7. import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
  8. import { CompleteFn } from '@firebase/util';
  9. import { EmulatorMockTokenOptions } from '@firebase/util';
  10. import { FirebaseApp } from '@firebase/app';
  11. import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
  12. import { FirebaseError } from '@firebase/util';
  13. import { _FirebaseService } from '@firebase/app';
  14. import { NextFn } from '@firebase/util';
  15. import { Provider } from '@firebase/component';
  16. import { Subscribe } from '@firebase/util';
  17. import { Unsubscribe } from '@firebase/util';
  18. /**
  19. * A function that is called if the event stream ends normally.
  20. */
  21. declare type CompleteFn_2 = () => void;
  22. /**
  23. * A lightweight wrapper around XMLHttpRequest with a
  24. * goog.net.XhrIo-like interface.
  25. *
  26. * You can create a new connection by invoking `newTextConnection()`,
  27. * `newBytesConnection()` or `newStreamConnection()`.
  28. */
  29. declare interface Connection<T extends ConnectionType> {
  30. /**
  31. * Sends a request to the provided URL.
  32. *
  33. * This method never rejects its promise. In case of encountering an error,
  34. * it sets an error code internally which can be accessed by calling
  35. * getErrorCode() by callers.
  36. */
  37. send(url: string, method: string, body?: ArrayBufferView | Blob | string | null, headers?: Headers_2): Promise<void>;
  38. getErrorCode(): ErrorCode;
  39. getStatus(): number;
  40. getResponse(): T;
  41. getErrorText(): string;
  42. /**
  43. * Abort the request.
  44. */
  45. abort(): void;
  46. getResponseHeader(header: string): string | null;
  47. addUploadProgressListener(listener: (p1: ProgressEvent) => void): void;
  48. removeUploadProgressListener(listener: (p1: ProgressEvent) => void): void;
  49. }
  50. /** Response type exposed by the networking APIs. */
  51. declare type ConnectionType = string | ArrayBuffer | Blob | NodeJS.ReadableStream;
  52. /**
  53. * Modify this {@link FirebaseStorage} instance to communicate with the Cloud Storage emulator.
  54. *
  55. * @param storage - The {@link FirebaseStorage} instance
  56. * @param host - The emulator host (ex: localhost)
  57. * @param port - The emulator port (ex: 5001)
  58. * @param options - Emulator options. `options.mockUserToken` is the mock auth
  59. * token to use for unit testing Security Rules.
  60. * @public
  61. */
  62. export declare function connectStorageEmulator(storage: FirebaseStorage, host: string, port: number, options?: {
  63. mockUserToken?: EmulatorMockTokenOptions | string;
  64. }): void;
  65. /**
  66. * @internal
  67. */
  68. export declare function _dataFromString(format: StringFormat, stringData: string): StringData;
  69. /**
  70. * Deletes the object at this location.
  71. * @public
  72. * @param ref - {@link StorageReference} for object to delete.
  73. * @returns A `Promise` that resolves if the deletion succeeds.
  74. */
  75. export declare function deleteObject(ref: StorageReference): Promise<void>;
  76. export { EmulatorMockTokenOptions }
  77. /**
  78. * Error codes for requests made by the the XhrIo wrapper.
  79. */
  80. declare enum ErrorCode {
  81. NO_ERROR = 0,
  82. NETWORK_ERROR = 1,
  83. ABORT = 2
  84. }
  85. /**
  86. * A function that is called with a `StorageError`
  87. * if the event stream ends due to an error.
  88. */
  89. declare type ErrorFn = (error: StorageError_2) => void;
  90. /** A function to handle an error. */
  91. declare type ErrorHandler = (connection: Connection<ConnectionType>, response: StorageError_2) => StorageError_2;
  92. /**
  93. * @license
  94. * Copyright 2017 Google LLC
  95. *
  96. * Licensed under the Apache License, Version 2.0 (the "License");
  97. * you may not use this file except in compliance with the License.
  98. * You may obtain a copy of the License at
  99. *
  100. * http://www.apache.org/licenses/LICENSE-2.0
  101. *
  102. * Unless required by applicable law or agreed to in writing, software
  103. * distributed under the License is distributed on an "AS IS" BASIS,
  104. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  105. * See the License for the specific language governing permissions and
  106. * limitations under the License.
  107. */
  108. /**
  109. * @param opt_elideCopy - If true, doesn't copy mutable input data
  110. * (e.g. Uint8Arrays). Pass true only if you know the objects will not be
  111. * modified after this blob's construction.
  112. *
  113. * @internal
  114. */
  115. export declare class _FbsBlob {
  116. private data_;
  117. private size_;
  118. private type_;
  119. constructor(data: Blob | Uint8Array | ArrayBuffer, elideCopy?: boolean);
  120. size(): number;
  121. type(): string;
  122. slice(startByte: number, endByte: number): _FbsBlob | null;
  123. static getBlob(...args: Array<string | _FbsBlob>): _FbsBlob | null;
  124. uploadData(): Blob | Uint8Array;
  125. }
  126. /**
  127. * A Firebase Storage instance.
  128. * @public
  129. */
  130. export declare interface FirebaseStorage extends _FirebaseService {
  131. /**
  132. * The {@link @firebase/app#FirebaseApp} associated with this `FirebaseStorage` instance.
  133. */
  134. readonly app: FirebaseApp;
  135. /**
  136. * The maximum time to retry uploads in milliseconds.
  137. */
  138. maxUploadRetryTime: number;
  139. /**
  140. * The maximum time to retry operations other than uploads or downloads in
  141. * milliseconds.
  142. */
  143. maxOperationRetryTime: number;
  144. }
  145. /**
  146. * A service that provides Firebase Storage Reference instances.
  147. * @param opt_url - gs:// url to a custom Storage Bucket
  148. *
  149. * @internal
  150. */
  151. export declare class _FirebaseStorageImpl implements FirebaseStorage {
  152. /**
  153. * FirebaseApp associated with this StorageService instance.
  154. */
  155. readonly app: FirebaseApp;
  156. readonly _authProvider: Provider<FirebaseAuthInternalName>;
  157. /**
  158. * @internal
  159. */
  160. readonly _appCheckProvider: Provider<AppCheckInternalComponentName>;
  161. /**
  162. * @internal
  163. */
  164. readonly _url?: string | undefined;
  165. readonly _firebaseVersion?: string | undefined;
  166. _bucket: _Location | null;
  167. /**
  168. * This string can be in the formats:
  169. * - host
  170. * - host:port
  171. */
  172. private _host;
  173. _protocol: string;
  174. protected readonly _appId: string | null;
  175. private readonly _requests;
  176. private _deleted;
  177. private _maxOperationRetryTime;
  178. private _maxUploadRetryTime;
  179. _overrideAuthToken?: string;
  180. constructor(
  181. /**
  182. * FirebaseApp associated with this StorageService instance.
  183. */
  184. app: FirebaseApp, _authProvider: Provider<FirebaseAuthInternalName>,
  185. /**
  186. * @internal
  187. */
  188. _appCheckProvider: Provider<AppCheckInternalComponentName>,
  189. /**
  190. * @internal
  191. */
  192. _url?: string | undefined, _firebaseVersion?: string | undefined);
  193. /**
  194. * The host string for this service, in the form of `host` or
  195. * `host:port`.
  196. */
  197. get host(): string;
  198. set host(host: string);
  199. /**
  200. * The maximum time to retry uploads in milliseconds.
  201. */
  202. get maxUploadRetryTime(): number;
  203. set maxUploadRetryTime(time: number);
  204. /**
  205. * The maximum time to retry operations other than uploads or downloads in
  206. * milliseconds.
  207. */
  208. get maxOperationRetryTime(): number;
  209. set maxOperationRetryTime(time: number);
  210. _getAuthToken(): Promise<string | null>;
  211. _getAppCheckToken(): Promise<string | null>;
  212. /**
  213. * Stop running requests and prevent more from being created.
  214. */
  215. _delete(): Promise<void>;
  216. /**
  217. * Returns a new firebaseStorage.Reference object referencing this StorageService
  218. * at the given Location.
  219. */
  220. _makeStorageReference(loc: _Location): _Reference;
  221. /**
  222. * @param requestInfo - HTTP RequestInfo object
  223. * @param authToken - Firebase auth token
  224. */
  225. _makeRequest<I extends ConnectionType, O>(requestInfo: RequestInfo_2<I, O>, requestFactory: () => Connection<I>, authToken: string | null, appCheckToken: string | null, retry?: boolean): Request_2<O>;
  226. makeRequestWithTokens<I extends ConnectionType, O>(requestInfo: RequestInfo_2<I, O>, requestFactory: () => Connection<I>): Promise<O>;
  227. }
  228. /**
  229. * The full set of object metadata, including read-only properties.
  230. * @public
  231. */
  232. export declare interface FullMetadata extends UploadMetadata {
  233. /**
  234. * The bucket this object is contained in.
  235. */
  236. bucket: string;
  237. /**
  238. * The full path of this object.
  239. */
  240. fullPath: string;
  241. /**
  242. * The object's generation.
  243. * {@link https://cloud.google.com/storage/docs/metadata#generation-number}
  244. */
  245. generation: string;
  246. /**
  247. * The object's metageneration.
  248. * {@link https://cloud.google.com/storage/docs/metadata#generation-number}
  249. */
  250. metageneration: string;
  251. /**
  252. * The short name of this object, which is the last component of the full path.
  253. * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
  254. */
  255. name: string;
  256. /**
  257. * The size of this object, in bytes.
  258. */
  259. size: number;
  260. /**
  261. * A date string representing when this object was created.
  262. */
  263. timeCreated: string;
  264. /**
  265. * A date string representing when this object was last updated.
  266. */
  267. updated: string;
  268. /**
  269. * Tokens to allow access to the downloatd URL.
  270. */
  271. downloadTokens: string[] | undefined;
  272. /**
  273. * `StorageReference` associated with this upload.
  274. */
  275. ref?: StorageReference | undefined;
  276. }
  277. /**
  278. * Downloads the data at the object's location. Returns an error if the object
  279. * is not found.
  280. *
  281. * To use this functionality, you have to whitelist your app's origin in your
  282. * Cloud Storage bucket. See also
  283. * https://cloud.google.com/storage/docs/configuring-cors
  284. *
  285. * This API is not available in Node.
  286. *
  287. * @public
  288. * @param ref - StorageReference where data should be downloaded.
  289. * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
  290. * retrieve.
  291. * @returns A Promise that resolves with a Blob containing the object's bytes
  292. */
  293. export declare function getBlob(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<Blob>;
  294. /**
  295. * Downloads the data at the object's location. Returns an error if the object
  296. * is not found.
  297. *
  298. * To use this functionality, you have to whitelist your app's origin in your
  299. * Cloud Storage bucket. See also
  300. * https://cloud.google.com/storage/docs/configuring-cors
  301. *
  302. * @public
  303. * @param ref - StorageReference where data should be downloaded.
  304. * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
  305. * retrieve.
  306. * @returns A Promise containing the object's bytes
  307. */
  308. export declare function getBytes(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<ArrayBuffer>;
  309. /**
  310. * @internal
  311. */
  312. export declare function _getChild(ref: StorageReference, childPath: string): _Reference;
  313. /**
  314. * Returns the download URL for the given {@link StorageReference}.
  315. * @public
  316. * @param ref - {@link StorageReference} to get the download URL for.
  317. * @returns A `Promise` that resolves with the download
  318. * URL for this object.
  319. */
  320. export declare function getDownloadURL(ref: StorageReference): Promise<string>;
  321. /**
  322. * A `Promise` that resolves with the metadata for this object. If this
  323. * object doesn't exist or metadata cannot be retreived, the promise is
  324. * rejected.
  325. * @public
  326. * @param ref - {@link StorageReference} to get metadata from.
  327. */
  328. export declare function getMetadata(ref: StorageReference): Promise<FullMetadata>;
  329. /**
  330. * Gets a {@link FirebaseStorage} instance for the given Firebase app.
  331. * @public
  332. * @param app - Firebase app to get {@link FirebaseStorage} instance for.
  333. * @param bucketUrl - The gs:// url to your Firebase Storage Bucket.
  334. * If not passed, uses the app's default Storage Bucket.
  335. * @returns A {@link FirebaseStorage} instance.
  336. */
  337. export declare function getStorage(app?: FirebaseApp, bucketUrl?: string): FirebaseStorage;
  338. /**
  339. * Downloads the data at the object's location. Raises an error event if the
  340. * object is not found.
  341. *
  342. * This API is only available in Node.
  343. *
  344. * @public
  345. * @param ref - StorageReference where data should be downloaded.
  346. * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
  347. * retrieve.
  348. * @returns A stream with the object's data as bytes
  349. */
  350. export declare function getStream(ref: StorageReference, maxDownloadSizeBytes?: number): NodeJS.ReadableStream;
  351. /**
  352. * @license
  353. * Copyright 2017 Google LLC
  354. *
  355. * Licensed under the Apache License, Version 2.0 (the "License");
  356. * you may not use this file except in compliance with the License.
  357. * You may obtain a copy of the License at
  358. *
  359. * http://www.apache.org/licenses/LICENSE-2.0
  360. *
  361. * Unless required by applicable law or agreed to in writing, software
  362. * distributed under the License is distributed on an "AS IS" BASIS,
  363. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  364. * See the License for the specific language governing permissions and
  365. * limitations under the License.
  366. */
  367. /// <reference types="node" />
  368. /** Network headers */
  369. declare type Headers_2 = Record<string, string>;
  370. /**
  371. * Internal enum for task state.
  372. */
  373. declare const enum InternalTaskState {
  374. RUNNING = "running",
  375. PAUSING = "pausing",
  376. PAUSED = "paused",
  377. SUCCESS = "success",
  378. CANCELING = "canceling",
  379. CANCELED = "canceled",
  380. ERROR = "error"
  381. }
  382. /**
  383. * @internal
  384. */
  385. export declare function _invalidArgument(message: string): StorageError_2;
  386. /**
  387. * @param name - The name of the operation that was invalid.
  388. *
  389. * @internal
  390. */
  391. export declare function _invalidRootOperation(name: string): StorageError_2;
  392. /**
  393. * List items (files) and prefixes (folders) under this storage reference.
  394. *
  395. * List API is only available for Firebase Rules Version 2.
  396. *
  397. * GCS is a key-blob store. Firebase Storage imposes the semantic of '/'
  398. * delimited folder structure.
  399. * Refer to GCS's List API if you want to learn more.
  400. *
  401. * To adhere to Firebase Rules's Semantics, Firebase Storage does not
  402. * support objects whose paths end with "/" or contain two consecutive
  403. * "/"s. Firebase Storage List API will filter these unsupported objects.
  404. * list() may fail if there are too many unsupported objects in the bucket.
  405. * @public
  406. *
  407. * @param ref - {@link StorageReference} to get list from.
  408. * @param options - See {@link ListOptions} for details.
  409. * @returns A `Promise` that resolves with the items and prefixes.
  410. * `prefixes` contains references to sub-folders and `items`
  411. * contains references to objects in this folder. `nextPageToken`
  412. * can be used to get the rest of the results.
  413. */
  414. export declare function list(ref: StorageReference, options?: ListOptions): Promise<ListResult>;
  415. /**
  416. * List all items (files) and prefixes (folders) under this storage reference.
  417. *
  418. * This is a helper method for calling list() repeatedly until there are
  419. * no more results. The default pagination size is 1000.
  420. *
  421. * Note: The results may not be consistent if objects are changed while this
  422. * operation is running.
  423. *
  424. * Warning: `listAll` may potentially consume too many resources if there are
  425. * too many results.
  426. * @public
  427. * @param ref - {@link StorageReference} to get list from.
  428. *
  429. * @returns A `Promise` that resolves with all the items and prefixes under
  430. * the current storage reference. `prefixes` contains references to
  431. * sub-directories and `items` contains references to objects in this
  432. * folder. `nextPageToken` is never returned.
  433. */
  434. export declare function listAll(ref: StorageReference): Promise<ListResult>;
  435. /**
  436. * The options `list()` accepts.
  437. * @public
  438. */
  439. export declare interface ListOptions {
  440. /**
  441. * If set, limits the total number of `prefixes` and `items` to return.
  442. * The default and maximum maxResults is 1000.
  443. */
  444. maxResults?: number | null;
  445. /**
  446. * The `nextPageToken` from a previous call to `list()`. If provided,
  447. * listing is resumed from the previous position.
  448. */
  449. pageToken?: string | null;
  450. }
  451. /**
  452. * Result returned by list().
  453. * @public
  454. */
  455. export declare interface ListResult {
  456. /**
  457. * References to prefixes (sub-folders). You can call list() on them to
  458. * get its contents.
  459. *
  460. * Folders are implicit based on '/' in the object paths.
  461. * For example, if a bucket has two objects '/a/b/1' and '/a/b/2', list('/a')
  462. * will return '/a/b' as a prefix.
  463. */
  464. prefixes: StorageReference[];
  465. /**
  466. * Objects in this directory.
  467. * You can call getMetadata() and getDownloadUrl() on them.
  468. */
  469. items: StorageReference[];
  470. /**
  471. * If set, there might be more results for this list. Use this token to resume the list.
  472. */
  473. nextPageToken?: string;
  474. }
  475. /**
  476. * @license
  477. * Copyright 2017 Google LLC
  478. *
  479. * Licensed under the Apache License, Version 2.0 (the "License");
  480. * you may not use this file except in compliance with the License.
  481. * You may obtain a copy of the License at
  482. *
  483. * http://www.apache.org/licenses/LICENSE-2.0
  484. *
  485. * Unless required by applicable law or agreed to in writing, software
  486. * distributed under the License is distributed on an "AS IS" BASIS,
  487. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  488. * See the License for the specific language governing permissions and
  489. * limitations under the License.
  490. */
  491. /**
  492. * Firebase Storage location data.
  493. *
  494. * @internal
  495. */
  496. export declare class _Location {
  497. readonly bucket: string;
  498. private path_;
  499. constructor(bucket: string, path: string);
  500. get path(): string;
  501. get isRoot(): boolean;
  502. fullServerUrl(): string;
  503. bucketOnlyServerUrl(): string;
  504. static makeFromBucketSpec(bucketString: string, host: string): _Location;
  505. static makeFromUrl(url: string, host: string): _Location;
  506. }
  507. /**
  508. * @fileoverview Documentation for the metadata format.
  509. */
  510. /**
  511. * The full set of object metadata, including read-only properties.
  512. */
  513. declare interface Metadata extends FullMetadata {
  514. [prop: string]: unknown;
  515. }
  516. /**
  517. * Function that is called once for each value in a stream of values.
  518. */
  519. declare type NextFn_2<T> = (value: T) => void;
  520. /**
  521. * Returns a {@link StorageReference} for the given url.
  522. * @param storage - {@link FirebaseStorage} instance.
  523. * @param url - URL. If empty, returns root reference.
  524. * @public
  525. */
  526. export declare function ref(storage: FirebaseStorage, url?: string): StorageReference;
  527. /**
  528. * Returns a {@link StorageReference} for the given path in the
  529. * default bucket.
  530. * @param storageOrRef - {@link FirebaseStorage} or {@link StorageReference}.
  531. * @param pathOrUrlStorage - path. If empty, returns root reference (if {@link FirebaseStorage}
  532. * instance provided) or returns same reference (if {@link StorageReference} provided).
  533. * @public
  534. */
  535. export declare function ref(storageOrRef: FirebaseStorage | StorageReference, path?: string): StorageReference;
  536. /**
  537. * Provides methods to interact with a bucket in the Firebase Storage service.
  538. * @internal
  539. * @param _location - An fbs.location, or the URL at
  540. * which to base this object, in one of the following forms:
  541. * gs://<bucket>/<object-path>
  542. * http[s]://firebasestorage.googleapis.com/
  543. * <api-version>/b/<bucket>/o/<object-path>
  544. * Any query or fragment strings will be ignored in the http[s]
  545. * format. If no value is passed, the storage object will use a URL based on
  546. * the project ID of the base firebase.App instance.
  547. */
  548. export declare class _Reference {
  549. private _service;
  550. _location: _Location;
  551. constructor(_service: _FirebaseStorageImpl, location: string | _Location);
  552. /**
  553. * Returns the URL for the bucket and path this object references,
  554. * in the form gs://<bucket>/<object-path>
  555. * @override
  556. */
  557. toString(): string;
  558. protected _newRef(service: _FirebaseStorageImpl, location: _Location): _Reference;
  559. /**
  560. * A reference to the root of this object's bucket.
  561. */
  562. get root(): _Reference;
  563. /**
  564. * The name of the bucket containing this reference's object.
  565. */
  566. get bucket(): string;
  567. /**
  568. * The full path of this object.
  569. */
  570. get fullPath(): string;
  571. /**
  572. * The short name of this object, which is the last component of the full path.
  573. * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
  574. */
  575. get name(): string;
  576. /**
  577. * The `StorageService` instance this `StorageReference` is associated with.
  578. */
  579. get storage(): _FirebaseStorageImpl;
  580. /**
  581. * A `StorageReference` pointing to the parent location of this `StorageReference`, or null if
  582. * this reference is the root.
  583. */
  584. get parent(): _Reference | null;
  585. /**
  586. * Utility function to throw an error in methods that do not accept a root reference.
  587. */
  588. _throwIfRoot(name: string): void;
  589. }
  590. declare interface Request_2<T> {
  591. getPromise(): Promise<T>;
  592. /**
  593. * Cancels the request. IMPORTANT: the promise may still be resolved with an
  594. * appropriate value (if the request is finished before you call this method,
  595. * but the promise has not yet been resolved), so don't just assume it will be
  596. * rejected if you call this function.
  597. * @param appDelete - True if the cancelation came from the app being deleted.
  598. */
  599. cancel(appDelete?: boolean): void;
  600. }
  601. /**
  602. * A function that converts a server response to the API type expected by the
  603. * SDK.
  604. *
  605. * @param I - the type of the backend's network response
  606. * @param O - the output response type used by the rest of the SDK.
  607. */
  608. declare type RequestHandler<I extends ConnectionType, O> = (connection: Connection<I>, response: I) => O;
  609. /**
  610. * Contains a fully specified request.
  611. *
  612. * @param I - the type of the backend's network response.
  613. * @param O - the output response type used by the rest of the SDK.
  614. */
  615. declare class RequestInfo_2<I extends ConnectionType, O> {
  616. url: string;
  617. method: string;
  618. /**
  619. * Returns the value with which to resolve the request's promise. Only called
  620. * if the request is successful. Throw from this function to reject the
  621. * returned Request's promise with the thrown error.
  622. * Note: The XhrIo passed to this function may be reused after this callback
  623. * returns. Do not keep a reference to it in any way.
  624. */
  625. handler: RequestHandler<I, O>;
  626. timeout: number;
  627. urlParams: UrlParams;
  628. headers: Headers_2;
  629. body: Blob | string | Uint8Array | null;
  630. errorHandler: ErrorHandler | null;
  631. /**
  632. * Called with the current number of bytes uploaded and total size (-1 if not
  633. * computable) of the request body (i.e. used to report upload progress).
  634. */
  635. progressCallback: ((p1: number, p2: number) => void) | null;
  636. successCodes: number[];
  637. additionalRetryCodes: number[];
  638. constructor(url: string, method: string,
  639. /**
  640. * Returns the value with which to resolve the request's promise. Only called
  641. * if the request is successful. Throw from this function to reject the
  642. * returned Request's promise with the thrown error.
  643. * Note: The XhrIo passed to this function may be reused after this callback
  644. * returns. Do not keep a reference to it in any way.
  645. */
  646. handler: RequestHandler<I, O>, timeout: number);
  647. }
  648. /**
  649. * Object metadata that can be set at any time.
  650. * @public
  651. */
  652. export declare interface SettableMetadata {
  653. /**
  654. * Served as the 'Cache-Control' header on object download.
  655. */
  656. cacheControl?: string | undefined;
  657. /**
  658. * Served as the 'Content-Disposition' header on object download.
  659. */
  660. contentDisposition?: string | undefined;
  661. /**
  662. * Served as the 'Content-Encoding' header on object download.
  663. */
  664. contentEncoding?: string | undefined;
  665. /**
  666. * Served as the 'Content-Language' header on object download.
  667. */
  668. contentLanguage?: string | undefined;
  669. /**
  670. * Served as the 'Content-Type' header on object download.
  671. */
  672. contentType?: string | undefined;
  673. /**
  674. * Additional user-defined custom metadata.
  675. */
  676. customMetadata?: {
  677. [key: string]: string;
  678. } | undefined;
  679. }
  680. /**
  681. * An error returned by the Firebase Storage SDK.
  682. * @public
  683. */
  684. export declare interface StorageError extends FirebaseError {
  685. /**
  686. * A server response message for the error, if applicable.
  687. */
  688. serverResponse: string | null;
  689. }
  690. /**
  691. * An error returned by the Firebase Storage SDK.
  692. * @public
  693. */
  694. declare class StorageError_2 extends FirebaseError {
  695. private status_;
  696. private readonly _baseMessage;
  697. /**
  698. * Stores custom error data unque to StorageError.
  699. */
  700. customData: {
  701. serverResponse: string | null;
  702. };
  703. /**
  704. * @param code - A StorageErrorCode string to be prefixed with 'storage/' and
  705. * added to the end of the message.
  706. * @param message - Error message.
  707. * @param status_ - Corresponding HTTP Status Code
  708. */
  709. constructor(code: StorageErrorCode, message: string, status_?: number);
  710. get status(): number;
  711. set status(status: number);
  712. /**
  713. * Compares a StorageErrorCode against this error's code, filtering out the prefix.
  714. */
  715. _codeEquals(code: StorageErrorCode): boolean;
  716. /**
  717. * Optional response message that was added by the server.
  718. */
  719. get serverResponse(): null | string;
  720. set serverResponse(serverResponse: string | null);
  721. }
  722. /**
  723. * @public
  724. * Error codes that can be attached to `StorageError`s.
  725. */
  726. declare const enum StorageErrorCode {
  727. UNKNOWN = "unknown",
  728. OBJECT_NOT_FOUND = "object-not-found",
  729. BUCKET_NOT_FOUND = "bucket-not-found",
  730. PROJECT_NOT_FOUND = "project-not-found",
  731. QUOTA_EXCEEDED = "quota-exceeded",
  732. UNAUTHENTICATED = "unauthenticated",
  733. UNAUTHORIZED = "unauthorized",
  734. UNAUTHORIZED_APP = "unauthorized-app",
  735. RETRY_LIMIT_EXCEEDED = "retry-limit-exceeded",
  736. INVALID_CHECKSUM = "invalid-checksum",
  737. CANCELED = "canceled",
  738. INVALID_EVENT_NAME = "invalid-event-name",
  739. INVALID_URL = "invalid-url",
  740. INVALID_DEFAULT_BUCKET = "invalid-default-bucket",
  741. NO_DEFAULT_BUCKET = "no-default-bucket",
  742. CANNOT_SLICE_BLOB = "cannot-slice-blob",
  743. SERVER_FILE_WRONG_SIZE = "server-file-wrong-size",
  744. NO_DOWNLOAD_URL = "no-download-url",
  745. INVALID_ARGUMENT = "invalid-argument",
  746. INVALID_ARGUMENT_COUNT = "invalid-argument-count",
  747. APP_DELETED = "app-deleted",
  748. INVALID_ROOT_OPERATION = "invalid-root-operation",
  749. INVALID_FORMAT = "invalid-format",
  750. INTERNAL_ERROR = "internal-error",
  751. UNSUPPORTED_ENVIRONMENT = "unsupported-environment"
  752. }
  753. /**
  754. * A stream observer for Firebase Storage.
  755. * @public
  756. */
  757. export declare interface StorageObserver<T> {
  758. next?: NextFn<T> | null;
  759. error?: (error: StorageError) => void | null;
  760. complete?: CompleteFn | null;
  761. }
  762. /**
  763. * An observer identical to the `Observer` defined in packages/util except the
  764. * error passed into the ErrorFn is specifically a `StorageError`.
  765. */
  766. declare interface StorageObserver_2<T> {
  767. /**
  768. * Function that is called once for each value in the event stream.
  769. */
  770. next?: NextFn_2<T>;
  771. /**
  772. * A function that is called with a `StorageError`
  773. * if the event stream ends due to an error.
  774. */
  775. error?: ErrorFn;
  776. /**
  777. * A function that is called if the event stream ends normally.
  778. */
  779. complete?: CompleteFn_2;
  780. }
  781. /**
  782. * Represents a reference to a Google Cloud Storage object. Developers can
  783. * upload, download, and delete objects, as well as get/set object metadata.
  784. * @public
  785. */
  786. export declare interface StorageReference {
  787. /**
  788. * Returns a gs:// URL for this object in the form
  789. * `gs://<bucket>/<path>/<to>/<object>`
  790. * @returns The gs:// URL.
  791. */
  792. toString(): string;
  793. /**
  794. * A reference to the root of this object's bucket.
  795. */
  796. root: StorageReference;
  797. /**
  798. * The name of the bucket containing this reference's object.
  799. */
  800. bucket: string;
  801. /**
  802. * The full path of this object.
  803. */
  804. fullPath: string;
  805. /**
  806. * The short name of this object, which is the last component of the full path.
  807. * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
  808. */
  809. name: string;
  810. /**
  811. * The {@link FirebaseStorage} instance associated with this reference.
  812. */
  813. storage: FirebaseStorage;
  814. /**
  815. * A reference pointing to the parent location of this reference, or null if
  816. * this reference is the root.
  817. */
  818. parent: StorageReference | null;
  819. }
  820. declare class StringData {
  821. data: Uint8Array;
  822. contentType: string | null;
  823. constructor(data: Uint8Array, contentType?: string | null);
  824. }
  825. /**
  826. * @license
  827. * Copyright 2017 Google LLC
  828. *
  829. * Licensed under the Apache License, Version 2.0 (the "License");
  830. * you may not use this file except in compliance with the License.
  831. * You may obtain a copy of the License at
  832. *
  833. * http://www.apache.org/licenses/LICENSE-2.0
  834. *
  835. * Unless required by applicable law or agreed to in writing, software
  836. * distributed under the License is distributed on an "AS IS" BASIS,
  837. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  838. * See the License for the specific language governing permissions and
  839. * limitations under the License.
  840. */
  841. /**
  842. * An enumeration of the possible string formats for upload.
  843. * @public
  844. */
  845. export declare type StringFormat = typeof StringFormat[keyof typeof StringFormat];
  846. /**
  847. * An enumeration of the possible string formats for upload.
  848. * @public
  849. */
  850. export declare const StringFormat: {
  851. /**
  852. * Indicates the string should be interpreted "raw", that is, as normal text.
  853. * The string will be interpreted as UTF-16, then uploaded as a UTF-8 byte
  854. * sequence.
  855. * Example: The string 'Hello! \\ud83d\\ude0a' becomes the byte sequence
  856. * 48 65 6c 6c 6f 21 20 f0 9f 98 8a
  857. */
  858. readonly RAW: "raw";
  859. /**
  860. * Indicates the string should be interpreted as base64-encoded data.
  861. * Padding characters (trailing '='s) are optional.
  862. * Example: The string 'rWmO++E6t7/rlw==' becomes the byte sequence
  863. * ad 69 8e fb e1 3a b7 bf eb 97
  864. */
  865. readonly BASE64: "base64";
  866. /**
  867. * Indicates the string should be interpreted as base64url-encoded data.
  868. * Padding characters (trailing '='s) are optional.
  869. * Example: The string 'rWmO--E6t7_rlw==' becomes the byte sequence
  870. * ad 69 8e fb e1 3a b7 bf eb 97
  871. */
  872. readonly BASE64URL: "base64url";
  873. /**
  874. * Indicates the string is a data URL, such as one obtained from
  875. * canvas.toDataURL().
  876. * Example: the string 'data:application/octet-stream;base64,aaaa'
  877. * becomes the byte sequence
  878. * 69 a6 9a
  879. * (the content-type "application/octet-stream" is also applied, but can
  880. * be overridden in the metadata object).
  881. */
  882. readonly DATA_URL: "data_url";
  883. };
  884. /**
  885. * Subscribes to an event stream.
  886. */
  887. declare type Subscribe_2<T> = (next?: NextFn_2<T> | StorageObserver_2<T>, error?: ErrorFn, complete?: CompleteFn_2) => Unsubscribe_2;
  888. /**
  889. * An event that is triggered on a task.
  890. * @public
  891. */
  892. export declare type TaskEvent = 'state_changed';
  893. /**
  894. * @license
  895. * Copyright 2017 Google LLC
  896. *
  897. * Licensed under the Apache License, Version 2.0 (the "License");
  898. * you may not use this file except in compliance with the License.
  899. * You may obtain a copy of the License at
  900. *
  901. * http://www.apache.org/licenses/LICENSE-2.0
  902. *
  903. * Unless required by applicable law or agreed to in writing, software
  904. * distributed under the License is distributed on an "AS IS" BASIS,
  905. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  906. * See the License for the specific language governing permissions and
  907. * limitations under the License.
  908. */
  909. /**
  910. * @fileoverview Enumerations used for upload tasks.
  911. */
  912. /**
  913. * An event that is triggered on a task.
  914. * @internal
  915. */
  916. export declare type _TaskEvent = string;
  917. /**
  918. * An event that is triggered on a task.
  919. * @internal
  920. */
  921. export declare const _TaskEvent: {
  922. /**
  923. * For this event,
  924. * <ul>
  925. * <li>The `next` function is triggered on progress updates and when the
  926. * task is paused/resumed with an `UploadTaskSnapshot` as the first
  927. * argument.</li>
  928. * <li>The `error` function is triggered if the upload is canceled or fails
  929. * for another reason.</li>
  930. * <li>The `complete` function is triggered if the upload completes
  931. * successfully.</li>
  932. * </ul>
  933. */
  934. STATE_CHANGED: string;
  935. };
  936. /**
  937. * Represents the current state of a running upload.
  938. * @public
  939. */
  940. export declare type TaskState = 'running' | 'paused' | 'success' | 'canceled' | 'error';
  941. /**
  942. * Represents the current state of a running upload.
  943. * @internal
  944. */
  945. export declare type _TaskState = typeof _TaskState[keyof typeof _TaskState];
  946. /**
  947. * Represents the current state of a running upload.
  948. * @internal
  949. */
  950. export declare const _TaskState: {
  951. /** The task is currently transferring data. */
  952. readonly RUNNING: "running";
  953. /** The task was paused by the user. */
  954. readonly PAUSED: "paused";
  955. /** The task completed successfully. */
  956. readonly SUCCESS: "success";
  957. /** The task was canceled. */
  958. readonly CANCELED: "canceled";
  959. /** The task failed with an error. */
  960. readonly ERROR: "error";
  961. };
  962. /**
  963. * Unsubscribes from a stream.
  964. */
  965. declare type Unsubscribe_2 = () => void;
  966. /**
  967. * Updates the metadata for this object.
  968. * @public
  969. * @param ref - {@link StorageReference} to update metadata for.
  970. * @param metadata - The new metadata for the object.
  971. * Only values that have been explicitly set will be changed. Explicitly
  972. * setting a value to null will remove the metadata.
  973. * @returns A `Promise` that resolves with the new metadata for this object.
  974. */
  975. export declare function updateMetadata(ref: StorageReference, metadata: SettableMetadata): Promise<FullMetadata>;
  976. /**
  977. * Uploads data to this object's location.
  978. * The upload is not resumable.
  979. * @public
  980. * @param ref - {@link StorageReference} where data should be uploaded.
  981. * @param data - The data to upload.
  982. * @param metadata - Metadata for the data to upload.
  983. * @returns A Promise containing an UploadResult
  984. */
  985. export declare function uploadBytes(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): Promise<UploadResult>;
  986. /**
  987. * Uploads data to this object's location.
  988. * The upload can be paused and resumed, and exposes progress updates.
  989. * @public
  990. * @param ref - {@link StorageReference} where data should be uploaded.
  991. * @param data - The data to upload.
  992. * @param metadata - Metadata for the data to upload.
  993. * @returns An UploadTask
  994. */
  995. export declare function uploadBytesResumable(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): UploadTask;
  996. /**
  997. * Object metadata that can be set at upload.
  998. * @public
  999. */
  1000. export declare interface UploadMetadata extends SettableMetadata {
  1001. /**
  1002. * A Base64-encoded MD5 hash of the object being uploaded.
  1003. */
  1004. md5Hash?: string | undefined;
  1005. }
  1006. /**
  1007. * Result returned from a non-resumable upload.
  1008. * @public
  1009. */
  1010. export declare interface UploadResult {
  1011. /**
  1012. * Contains the metadata sent back from the server.
  1013. */
  1014. readonly metadata: FullMetadata;
  1015. /**
  1016. * The reference that spawned this upload.
  1017. */
  1018. readonly ref: StorageReference;
  1019. }
  1020. /**
  1021. * Uploads a string to this object's location.
  1022. * The upload is not resumable.
  1023. * @public
  1024. * @param ref - {@link StorageReference} where string should be uploaded.
  1025. * @param value - The string to upload.
  1026. * @param format - The format of the string to upload.
  1027. * @param metadata - Metadata for the string to upload.
  1028. * @returns A Promise containing an UploadResult
  1029. */
  1030. export declare function uploadString(ref: StorageReference, value: string, format?: StringFormat, metadata?: UploadMetadata): Promise<UploadResult>;
  1031. /**
  1032. * Represents the process of uploading an object. Allows you to monitor and
  1033. * manage the upload.
  1034. * @public
  1035. */
  1036. export declare interface UploadTask {
  1037. /**
  1038. * Cancels a running task. Has no effect on a complete or failed task.
  1039. * @returns True if the cancel had an effect.
  1040. */
  1041. cancel(): boolean;
  1042. /**
  1043. * Equivalent to calling `then(null, onRejected)`.
  1044. */
  1045. catch(onRejected: (error: StorageError) => unknown): Promise<unknown>;
  1046. /**
  1047. * Listens for events on this task.
  1048. *
  1049. * Events have three callback functions (referred to as `next`, `error`, and
  1050. * `complete`).
  1051. *
  1052. * If only the event is passed, a function that can be used to register the
  1053. * callbacks is returned. Otherwise, the callbacks are passed after the event.
  1054. *
  1055. * Callbacks can be passed either as three separate arguments <em>or</em> as the
  1056. * `next`, `error`, and `complete` properties of an object. Any of the three
  1057. * callbacks is optional, as long as at least one is specified. In addition,
  1058. * when you add your callbacks, you get a function back. You can call this
  1059. * function to unregister the associated callbacks.
  1060. *
  1061. * @example **Pass callbacks separately or in an object.**
  1062. * ```javascript
  1063. * var next = function(snapshot) {};
  1064. * var error = function(error) {};
  1065. * var complete = function() {};
  1066. *
  1067. * // The first example.
  1068. * uploadTask.on(
  1069. * firebase.storage.TaskEvent.STATE_CHANGED,
  1070. * next,
  1071. * error,
  1072. * complete);
  1073. *
  1074. * // This is equivalent to the first example.
  1075. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
  1076. * 'next': next,
  1077. * 'error': error,
  1078. * 'complete': complete
  1079. * });
  1080. *
  1081. * // This is equivalent to the first example.
  1082. * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  1083. * subscribe(next, error, complete);
  1084. *
  1085. * // This is equivalent to the first example.
  1086. * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  1087. * subscribe({
  1088. * 'next': next,
  1089. * 'error': error,
  1090. * 'complete': complete
  1091. * });
  1092. * ```
  1093. *
  1094. * @example **Any callback is optional.**
  1095. * ```javascript
  1096. * // Just listening for completion, this is legal.
  1097. * uploadTask.on(
  1098. * firebase.storage.TaskEvent.STATE_CHANGED,
  1099. * null,
  1100. * null,
  1101. * function() {
  1102. * console.log('upload complete!');
  1103. * });
  1104. *
  1105. * // Just listening for progress/state changes, this is legal.
  1106. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, function(snapshot) {
  1107. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  1108. * console.log(percent + "% done");
  1109. * });
  1110. *
  1111. * // This is also legal.
  1112. * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
  1113. * 'complete': function() {
  1114. * console.log('upload complete!');
  1115. * }
  1116. * });
  1117. * ```
  1118. *
  1119. * @example **Use the returned function to remove callbacks.**
  1120. * ```javascript
  1121. * var unsubscribe = uploadTask.on(
  1122. * firebase.storage.TaskEvent.STATE_CHANGED,
  1123. * function(snapshot) {
  1124. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  1125. * console.log(percent + "% done");
  1126. * // Stop after receiving one update.
  1127. * unsubscribe();
  1128. * });
  1129. *
  1130. * // This code is equivalent to the above.
  1131. * var handle = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
  1132. * unsubscribe = handle(function(snapshot) {
  1133. * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
  1134. * console.log(percent + "% done");
  1135. * // Stop after receiving one update.
  1136. * unsubscribe();
  1137. * });
  1138. * ```
  1139. *
  1140. * @param event - The type of event to listen for.
  1141. * @param nextOrObserver -
  1142. * The `next` function, which gets called for each item in
  1143. * the event stream, or an observer object with some or all of these three
  1144. * properties (`next`, `error`, `complete`).
  1145. * @param error - A function that gets called with a `StorageError`
  1146. * if the event stream ends due to an error.
  1147. * @param completed - A function that gets called if the
  1148. * event stream ends normally.
  1149. * @returns
  1150. * If only the event argument is passed, returns a function you can use to
  1151. * add callbacks (see the examples above). If more than just the event
  1152. * argument is passed, returns a function you can call to unregister the
  1153. * callbacks.
  1154. */
  1155. on(event: TaskEvent, nextOrObserver?: StorageObserver<UploadTaskSnapshot> | null | ((snapshot: UploadTaskSnapshot) => unknown), error?: ((a: StorageError) => unknown) | null, complete?: Unsubscribe | null): Unsubscribe | Subscribe<UploadTaskSnapshot>;
  1156. /**
  1157. * Pauses a currently running task. Has no effect on a paused or failed task.
  1158. * @returns True if the operation took effect, false if ignored.
  1159. */
  1160. pause(): boolean;
  1161. /**
  1162. * Resumes a paused task. Has no effect on a currently running or failed task.
  1163. * @returns True if the operation took effect, false if ignored.
  1164. */
  1165. resume(): boolean;
  1166. /**
  1167. * A snapshot of the current task state.
  1168. */
  1169. snapshot: UploadTaskSnapshot;
  1170. /**
  1171. * This object behaves like a Promise, and resolves with its snapshot data
  1172. * when the upload completes.
  1173. * @param onFulfilled - The fulfillment callback. Promise chaining works as normal.
  1174. * @param onRejected - The rejection callback.
  1175. */
  1176. then(onFulfilled?: ((snapshot: UploadTaskSnapshot) => unknown) | null, onRejected?: ((error: StorageError) => unknown) | null): Promise<unknown>;
  1177. }
  1178. /**
  1179. * Represents a blob being uploaded. Can be used to pause/resume/cancel the
  1180. * upload and manage callbacks for various events.
  1181. * @internal
  1182. */
  1183. export declare class _UploadTask {
  1184. private _ref;
  1185. /**
  1186. * The data to be uploaded.
  1187. */
  1188. _blob: _FbsBlob;
  1189. /**
  1190. * Metadata related to the upload.
  1191. */
  1192. _metadata: Metadata | null;
  1193. private _mappings;
  1194. /**
  1195. * Number of bytes transferred so far.
  1196. */
  1197. _transferred: number;
  1198. private _needToFetchStatus;
  1199. private _needToFetchMetadata;
  1200. private _observers;
  1201. private _resumable;
  1202. /**
  1203. * Upload state.
  1204. */
  1205. _state: InternalTaskState;
  1206. private _error?;
  1207. private _uploadUrl?;
  1208. private _request?;
  1209. private _chunkMultiplier;
  1210. private _errorHandler;
  1211. private _metadataErrorHandler;
  1212. private _resolve?;
  1213. private _reject?;
  1214. private pendingTimeout?;
  1215. private _promise;
  1216. private sleepTime;
  1217. private maxSleepTime;
  1218. isExponentialBackoffExpired(): boolean;
  1219. /**
  1220. * @param ref - The firebaseStorage.Reference object this task came
  1221. * from, untyped to avoid cyclic dependencies.
  1222. * @param blob - The blob to upload.
  1223. */
  1224. constructor(ref: _Reference, blob: _FbsBlob, metadata?: Metadata | null);
  1225. private _makeProgressCallback;
  1226. private _shouldDoResumable;
  1227. private _start;
  1228. private _resolveToken;
  1229. private _createResumable;
  1230. private _fetchStatus;
  1231. private _continueUpload;
  1232. private _increaseMultiplier;
  1233. private _fetchMetadata;
  1234. private _oneShotUpload;
  1235. private _updateProgress;
  1236. private _transition;
  1237. private completeTransitions_;
  1238. /**
  1239. * A snapshot of the current task state.
  1240. */
  1241. get snapshot(): UploadTaskSnapshot;
  1242. /**
  1243. * Adds a callback for an event.
  1244. * @param type - The type of event to listen for.
  1245. * @param nextOrObserver -
  1246. * The `next` function, which gets called for each item in
  1247. * the event stream, or an observer object with some or all of these three
  1248. * properties (`next`, `error`, `complete`).
  1249. * @param error - A function that gets called with a `StorageError`
  1250. * if the event stream ends due to an error.
  1251. * @param completed - A function that gets called if the
  1252. * event stream ends normally.
  1253. * @returns
  1254. * If only the event argument is passed, returns a function you can use to
  1255. * add callbacks (see the examples above). If more than just the event
  1256. * argument is passed, returns a function you can call to unregister the
  1257. * callbacks.
  1258. */
  1259. on(type: _TaskEvent, nextOrObserver?: StorageObserver<UploadTaskSnapshot> | null | ((snapshot: UploadTaskSnapshot) => unknown), error?: ((a: StorageError_2) => unknown) | null, completed?: CompleteFn | null): Unsubscribe_2 | Subscribe_2<UploadTaskSnapshot>;
  1260. /**
  1261. * This object behaves like a Promise, and resolves with its snapshot data
  1262. * when the upload completes.
  1263. * @param onFulfilled - The fulfillment callback. Promise chaining works as normal.
  1264. * @param onRejected - The rejection callback.
  1265. */
  1266. then<U>(onFulfilled?: ((value: UploadTaskSnapshot) => U | Promise<U>) | null, onRejected?: ((error: StorageError_2) => U | Promise<U>) | null): Promise<U>;
  1267. /**
  1268. * Equivalent to calling `then(null, onRejected)`.
  1269. */
  1270. catch<T>(onRejected: (p1: StorageError_2) => T | Promise<T>): Promise<T>;
  1271. /**
  1272. * Adds the given observer.
  1273. */
  1274. private _addObserver;
  1275. /**
  1276. * Removes the given observer.
  1277. */
  1278. private _removeObserver;
  1279. private _notifyObservers;
  1280. private _finishPromise;
  1281. private _notifyObserver;
  1282. /**
  1283. * Resumes a paused task. Has no effect on a currently running or failed task.
  1284. * @returns True if the operation took effect, false if ignored.
  1285. */
  1286. resume(): boolean;
  1287. /**
  1288. * Pauses a currently running task. Has no effect on a paused or failed task.
  1289. * @returns True if the operation took effect, false if ignored.
  1290. */
  1291. pause(): boolean;
  1292. /**
  1293. * Cancels a currently running or paused task. Has no effect on a complete or
  1294. * failed task.
  1295. * @returns True if the operation took effect, false if ignored.
  1296. */
  1297. cancel(): boolean;
  1298. }
  1299. /**
  1300. * Holds data about the current state of the upload task.
  1301. * @public
  1302. */
  1303. export declare interface UploadTaskSnapshot {
  1304. /**
  1305. * The number of bytes that have been successfully uploaded so far.
  1306. */
  1307. bytesTransferred: number;
  1308. /**
  1309. * Before the upload completes, contains the metadata sent to the server.
  1310. * After the upload completes, contains the metadata sent back from the server.
  1311. */
  1312. metadata: FullMetadata;
  1313. /**
  1314. * The reference that spawned this snapshot's upload task.
  1315. */
  1316. ref: StorageReference;
  1317. /**
  1318. * The current state of the task.
  1319. */
  1320. state: TaskState;
  1321. /**
  1322. * The task of which this is a snapshot.
  1323. */
  1324. task: UploadTask;
  1325. /**
  1326. * The total number of bytes to be uploaded.
  1327. */
  1328. totalBytes: number;
  1329. }
  1330. /**
  1331. * Type for url params stored in RequestInfo.
  1332. */
  1333. declare interface UrlParams {
  1334. [name: string]: string | number;
  1335. }
  1336. export { }