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