前往主控台

Represents a reference to a Google Cloud Storage object. Developers can upload, download, and delete objects, as well as get/set object metadata.

Index

Properties

bucket

bucket: string

The name of the bucket containing this reference's object.

fullPath

fullPath: string

The full path of this object.

name

name: string

The short name of this object, which is the last component of the full path. For example, if fullPath is 'full/path/image.png', name is 'image.png'.

parent

parent: Reference | null

A reference pointing to the parent location of this reference, or null if this reference is the root.

root

root: Reference

A reference to the root of this reference's bucket.

storage

storage: Storage

The storage service associated with this reference.

Methods

child

  • child(path: string): Reference
  • Returns a reference to a relative path from this reference.

    Parameters

    • path: string

      The relative path from this reference. Leading, trailing, and consecutive slashes are removed.

    Returns Reference

    The reference to the given path.

delete

  • delete(): Promise<any>
  • Deletes the object at this reference's location.

    Returns Promise<any>

    A Promise that resolves if the deletion succeeded and rejects if it failed, including if the object didn't exist.

getDownloadURL

  • getDownloadURL(): Promise<any>
  • Fetches a long lived download URL for this object.

    Returns Promise<any>

    A Promise that resolves with the download URL or rejects if the fetch failed, including if the object did not exist.

getMetadata

  • getMetadata(): Promise<any>
  • Fetches metadata for the object at this location, if one exists.

    Returns Promise<any>

    A Promise that resolves with the metadata, or rejects if the fetch failed, including if the object did not exist.

put

  • put(data: any | any | any, metadata?: UploadMetadata): UploadTask
  • Uploads data to this reference's location.

    Parameters

    • data: any | any | any

      The data to upload.

    • Optional metadata: UploadMetadata

      Metadata for the newly uploaded object.

    Returns UploadTask

    An object that can be used to monitor and manage the upload.

putString

  • putString(data: string, format?: StringFormat, metadata?: UploadMetadata): UploadTask
  • Uploads string data to this reference's location.

    throws

    If the format is not an allowed format, or if the given string doesn't conform to the specified format.

    Parameters

    • data: string

      The string to upload.

    • Optional format: StringFormat

      The format of the string to upload.

    • Optional metadata: UploadMetadata

      Metadata for the newly uploaded object.

    Returns UploadTask

toString

  • toString(): string
  • Returns a gs:// URL for this object in the form gs://<bucket>/<path>/<to>/<object>

    Returns string

    The gs:// URL.

updateMetadata

  • updateMetadata(metadata: SettableMetadata): Promise<any>
  • Updates the metadata for the object at this location, if one exists.

    Parameters

    • metadata: SettableMetadata

      The new metadata. Setting a property to 'null' removes it on the server, while leaving a property as 'undefined' has no effect.

    Returns Promise<any>

    A Promise that resolves with the full updated metadata or rejects if the updated failed, including if the object did not exist.