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.

reference.d.ts 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /**
  2. * @license
  3. * Copyright 2019 Google LLC
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /// <reference types="node" />
  18. import { Location } from './implementation/location';
  19. import { ListOptions, UploadResult } from './public-types';
  20. import { StringFormat } from './implementation/string';
  21. import { Metadata } from './metadata';
  22. import { FirebaseStorageImpl } from './service';
  23. import { ListResult } from './list';
  24. import { UploadTask } from './task';
  25. /**
  26. * Provides methods to interact with a bucket in the Firebase Storage service.
  27. * @internal
  28. * @param _location - An fbs.location, or the URL at
  29. * which to base this object, in one of the following forms:
  30. * gs://<bucket>/<object-path>
  31. * http[s]://firebasestorage.googleapis.com/
  32. * <api-version>/b/<bucket>/o/<object-path>
  33. * Any query or fragment strings will be ignored in the http[s]
  34. * format. If no value is passed, the storage object will use a URL based on
  35. * the project ID of the base firebase.App instance.
  36. */
  37. export declare class Reference {
  38. private _service;
  39. _location: Location;
  40. constructor(_service: FirebaseStorageImpl, location: string | Location);
  41. /**
  42. * Returns the URL for the bucket and path this object references,
  43. * in the form gs://<bucket>/<object-path>
  44. * @override
  45. */
  46. toString(): string;
  47. protected _newRef(service: FirebaseStorageImpl, location: Location): Reference;
  48. /**
  49. * A reference to the root of this object's bucket.
  50. */
  51. get root(): Reference;
  52. /**
  53. * The name of the bucket containing this reference's object.
  54. */
  55. get bucket(): string;
  56. /**
  57. * The full path of this object.
  58. */
  59. get fullPath(): string;
  60. /**
  61. * The short name of this object, which is the last component of the full path.
  62. * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
  63. */
  64. get name(): string;
  65. /**
  66. * The `StorageService` instance this `StorageReference` is associated with.
  67. */
  68. get storage(): FirebaseStorageImpl;
  69. /**
  70. * A `StorageReference` pointing to the parent location of this `StorageReference`, or null if
  71. * this reference is the root.
  72. */
  73. get parent(): Reference | null;
  74. /**
  75. * Utility function to throw an error in methods that do not accept a root reference.
  76. */
  77. _throwIfRoot(name: string): void;
  78. }
  79. /**
  80. * Download the bytes at the object's location.
  81. * @returns A Promise containing the downloaded bytes.
  82. */
  83. export declare function getBytesInternal(ref: Reference, maxDownloadSizeBytes?: number): Promise<ArrayBuffer>;
  84. /**
  85. * Download the bytes at the object's location.
  86. * @returns A Promise containing the downloaded blob.
  87. */
  88. export declare function getBlobInternal(ref: Reference, maxDownloadSizeBytes?: number): Promise<Blob>;
  89. /** Stream the bytes at the object's location. */
  90. export declare function getStreamInternal(ref: Reference, maxDownloadSizeBytes?: number): NodeJS.ReadableStream;
  91. /**
  92. * Uploads data to this object's location.
  93. * The upload is not resumable.
  94. *
  95. * @param ref - StorageReference where data should be uploaded.
  96. * @param data - The data to upload.
  97. * @param metadata - Metadata for the newly uploaded data.
  98. * @returns A Promise containing an UploadResult
  99. */
  100. export declare function uploadBytes(ref: Reference, data: Blob | Uint8Array | ArrayBuffer, metadata?: Metadata): Promise<UploadResult>;
  101. /**
  102. * Uploads data to this object's location.
  103. * The upload can be paused and resumed, and exposes progress updates.
  104. * @public
  105. * @param ref - StorageReference where data should be uploaded.
  106. * @param data - The data to upload.
  107. * @param metadata - Metadata for the newly uploaded data.
  108. * @returns An UploadTask
  109. */
  110. export declare function uploadBytesResumable(ref: Reference, data: Blob | Uint8Array | ArrayBuffer, metadata?: Metadata): UploadTask;
  111. /**
  112. * Uploads a string to this object's location.
  113. * The upload is not resumable.
  114. * @public
  115. * @param ref - StorageReference where string should be uploaded.
  116. * @param value - The string to upload.
  117. * @param format - The format of the string to upload.
  118. * @param metadata - Metadata for the newly uploaded string.
  119. * @returns A Promise containing an UploadResult
  120. */
  121. export declare function uploadString(ref: Reference, value: string, format?: StringFormat, metadata?: Metadata): Promise<UploadResult>;
  122. /**
  123. * List all items (files) and prefixes (folders) under this storage reference.
  124. *
  125. * This is a helper method for calling list() repeatedly until there are
  126. * no more results. The default pagination size is 1000.
  127. *
  128. * Note: The results may not be consistent if objects are changed while this
  129. * operation is running.
  130. *
  131. * Warning: listAll may potentially consume too many resources if there are
  132. * too many results.
  133. * @public
  134. * @param ref - StorageReference to get list from.
  135. *
  136. * @returns A Promise that resolves with all the items and prefixes under
  137. * the current storage reference. `prefixes` contains references to
  138. * sub-directories and `items` contains references to objects in this
  139. * folder. `nextPageToken` is never returned.
  140. */
  141. export declare function listAll(ref: Reference): Promise<ListResult>;
  142. /**
  143. * List items (files) and prefixes (folders) under this storage reference.
  144. *
  145. * List API is only available for Firebase Rules Version 2.
  146. *
  147. * GCS is a key-blob store. Firebase Storage imposes the semantic of '/'
  148. * delimited folder structure.
  149. * Refer to GCS's List API if you want to learn more.
  150. *
  151. * To adhere to Firebase Rules's Semantics, Firebase Storage does not
  152. * support objects whose paths end with "/" or contain two consecutive
  153. * "/"s. Firebase Storage List API will filter these unsupported objects.
  154. * list() may fail if there are too many unsupported objects in the bucket.
  155. * @public
  156. *
  157. * @param ref - StorageReference to get list from.
  158. * @param options - See ListOptions for details.
  159. * @returns A Promise that resolves with the items and prefixes.
  160. * `prefixes` contains references to sub-folders and `items`
  161. * contains references to objects in this folder. `nextPageToken`
  162. * can be used to get the rest of the results.
  163. */
  164. export declare function list(ref: Reference, options?: ListOptions | null): Promise<ListResult>;
  165. /**
  166. * A `Promise` that resolves with the metadata for this object. If this
  167. * object doesn't exist or metadata cannot be retreived, the promise is
  168. * rejected.
  169. * @public
  170. * @param ref - StorageReference to get metadata from.
  171. */
  172. export declare function getMetadata(ref: Reference): Promise<Metadata>;
  173. /**
  174. * Updates the metadata for this object.
  175. * @public
  176. * @param ref - StorageReference to update metadata for.
  177. * @param metadata - The new metadata for the object.
  178. * Only values that have been explicitly set will be changed. Explicitly
  179. * setting a value to null will remove the metadata.
  180. * @returns A `Promise` that resolves
  181. * with the new metadata for this object.
  182. * See `firebaseStorage.Reference.prototype.getMetadata`
  183. */
  184. export declare function updateMetadata(ref: Reference, metadata: Partial<Metadata>): Promise<Metadata>;
  185. /**
  186. * Returns the download URL for the given Reference.
  187. * @public
  188. * @returns A `Promise` that resolves with the download
  189. * URL for this object.
  190. */
  191. export declare function getDownloadURL(ref: Reference): Promise<string>;
  192. /**
  193. * Deletes the object at this location.
  194. * @public
  195. * @param ref - StorageReference for object to delete.
  196. * @returns A `Promise` that resolves if the deletion succeeds.
  197. */
  198. export declare function deleteObject(ref: Reference): Promise<void>;
  199. /**
  200. * Returns reference for object obtained by appending `childPath` to `ref`.
  201. *
  202. * @param ref - StorageReference to get child of.
  203. * @param childPath - Child path from provided ref.
  204. * @returns A reference to the object obtained by
  205. * appending childPath, removing any duplicate, beginning, or trailing
  206. * slashes.
  207. *
  208. */
  209. export declare function _getChild(ref: Reference, childPath: string): Reference;