firebase_functions.storage_fn module

Functions to handle events from Google Cloud Storage.

Classes

CustomerEncryption

class firebase_functions.storage_fn.CustomerEncryption(encryption_algorithm: str, key_sha256: str)

Bases: object

Metadata of customer-supplied encryption key, if the object is encrypted by such a key.

encryption_algorithm: str

The encryption algorithm.

key_sha256: str

SHA256 hash value of the encryption key.

StorageObjectData

class firebase_functions.storage_fn.StorageObjectData(bucket: str, cache_control: str | None, component_count: int | None, content_disposition: str | None, content_encoding: str | None, content_language: str | None, content_type: str | None, crc32c: str | None, customer_encryption: CustomerEncryption | None, etag: str | None, generation: int, id: str, kind: str | None, md5_hash: str | None, media_link: str | None, metadata: dict[str, str] | None, metageneration: int, name: str, self_link: str | None, size: int, storage_class: str, time_created: str | None, time_deleted: str | None, time_storage_class_updated: str | None, updated: str | None)

Bases: object

An object within Google Cloud Storage.

bucket: str

The name of the bucket containing this object.

cache_control: str | None

Cache-Control directive for the object data, matching [RFC 7234 §5.2]([https://tools.ietf.org/html/rfc7234#section-5.2"]).

component_count: int | None

Number of underlying components that make up this object. Components are accumulated by compose operations.

content_disposition: str | None

Content-Disposition of the object data, matching [RFC 6266]([https://tools.ietf.org/html/rfc6266"]).

content_encoding: str | None

Content-Encoding of the object data, matching [RFC 7231 §3.1.2.2](https://tools.ietf.org/html/rfc7231#section-3.1.2.2)

content_language: str | None

Content-Language of the object data, matching [RFC 7231 §3.1.3.2](https://tools.ietf.org/html/rfc7231#section-3.1.3.2)

content_type: str | None

Content-Type of the object data, matching [RFC 7231 §3.1.1.5](https://tools.ietf.org/html/rfc7231#section-3.1.1.5) If an object is stored without a Content-Type, it is served as application/octet-stream.

crc32c: str | None

CRC32c checksum. For more information about using the CRC32c checksum, see [Hashes and ETags: Best Practices](https://cloud.google.com/storage/docs/hashes-etags#_JSONAPI).

customer_encryption: CustomerEncryption | None

Metadata of customer-supplied encryption key, if the object is encrypted by such a key.

etag: str | None

HTTP 1.1 Entity tag for the object.

generation: int

The content generation of this object. Used for object versioning.

id: str

The ID of the object, including the bucket name, object name, and generation number.

kind: str | None

The kind of item this is. For objects, this is always storage#object.

md5_hash: str | None

MD5 hash of the data; encoded using base64.

Media download link.

metadata: dict[str, str] | None

User-provided metadata, in key/value pairs.

metageneration: int

The version of the metadata for this object at this generation. Used for preconditions and for detecting changes in metadata. A metageneration number is only meaningful in the context of a particular generation of a particular object.

name: str

The name of the object.

The link to this object.

size: int

Content-Length of the data in bytes.

storage_class: str

Storage class of the object.

time_created: str | None

The creation time of the object.

time_deleted: str | None

The deletion time of the object.

time_storage_class_updated: str | None

The time at which the object's storage class was last changed.

updated: str | None

The modification time of the object metadata.

Functions

on_object_archived

firebase_functions.storage_fn.on_object_archived(**kwargs) Callable[[Callable[[CloudEvent[StorageObjectData]], None]], Callable[[CloudEvent[StorageObjectData]], None]]

Event handler sent only when a bucket has enabled object versioning. This event indicates that the live version of an object has become an archived version, either because it was archived or because it was overwritten by the upload of an object of the same name.

Example:

@on_object_archived()
def example(event: CloudEvent[StorageObjectData]) -> None:
    pass
Parameters:

**kwargs (as firebase_functions.options.StorageOptions) -- Storage options.

Return type:

typing.Callable [ [ firebase_functions.core.CloudEvent [ firebase_functions.storage.StorageObjectData ] ], None ] A function that takes a CloudEvent and returns None.

on_object_deleted

firebase_functions.storage_fn.on_object_deleted(**kwargs) Callable[[Callable[[CloudEvent[StorageObjectData]], None]], Callable[[CloudEvent[StorageObjectData]], None]]

Event handler which fires every time a Google Cloud Storage deletion occurs. Sent when an object has been permanently deleted. This includes objects that are overwritten or are deleted as part of the bucket's lifecycle configuration. For buckets with object versioning enabled, this is not sent when an object is archived, even if archival occurs via the storage.objects.delete method.

Example:

@on_object_deleted()
def example(event: CloudEvent[StorageObjectData]) -> None:
    pass
Parameters:

**kwargs (as firebase_functions.options.StorageOptions) -- Storage options.

Return type:

typing.Callable [ [ firebase_functions.core.CloudEvent [ firebase_functions.storage.StorageObjectData ] ], None ] A function that takes a CloudEvent and returns None.

on_object_finalized

firebase_functions.storage_fn.on_object_finalized(**kwargs) Callable[[Callable[[CloudEvent[StorageObjectData]], None]], Callable[[CloudEvent[StorageObjectData]], None]]

Event handler which fires every time a Google Cloud Storage object creation occurs. Sent when a new object (or a new generation of an existing object) is successfully created in the bucket. This includes copying or rewriting an existing object. A failed upload does not trigger this event.

Example:

@on_object_finalized()
def example(event: CloudEvent[StorageObjectData]) -> None:
    pass
Parameters:

**kwargs (as firebase_functions.options.StorageOptions) -- Storage options.

Return type:

typing.Callable [ [ firebase_functions.core.CloudEvent [ firebase_functions.storage.StorageObjectData ] ], None ] A function that takes a CloudEvent and returns None.

on_object_metadata_updated

firebase_functions.storage_fn.on_object_metadata_updated(**kwargs) Callable[[Callable[[CloudEvent[StorageObjectData]], None]], Callable[[CloudEvent[StorageObjectData]], None]]

Event handler which fires every time the metadata of an existing object changes.

Example:

@on_object_metadata_updated()
def example(event: CloudEvent[StorageObjectData]) -> None:
    pass
Parameters:

**kwargs (as firebase_functions.options.StorageOptions) -- Storage options.

Return type:

typing.Callable [ [ firebase_functions.core.CloudEvent [ firebase_functions.storage.StorageObjectData ] ], None ] A function that takes a CloudEvent and returns None.