Storage

Utilities for interacting with Google Cloud Storage.

API Reference

storage.generate_image_path(post_id: str, ext: str) → pathlib.Path[source]

Generates the full path to be passed to upload_data().

Parameters:
  • post_id – Output filename, usually gathered from an upload request.
  • ext – Output extension, usually gathered from an upload request.
Returns:

Full path to be passed to upload_data().

storage.generate_transcoding_path() → pathlib.Path[source]

Generates a directory path that can be used for publishing transcode events.

Returns:
storage.generate_video_path(output_name: str, ext: str) → pathlib.Path[source]

Generates the full path to be passed to upload_data().

Parameters:
  • output_name – Output filename, usually gathered from an upload request.
  • ext – Output extension, usually gathered from an upload request.
Returns:

Full path to be passed to upload_data().

storage.get_image_url(filename: str) → typing.Union[str, NoneType][source]

Gets an image’s public url based on the filename without extension.

Parameters:filename
Returns:Image’s public URL.
storage.get_public_url(filename: str) → typing.Union[str, NoneType][source]

Get’s a files public url based on the filename. Could be a video or image.

Parameters:filename
Returns:Public URL
storage.get_video_url(filename: str) → typing.Union[str, NoneType][source]

Gets a video’s public url based on the filename without extension.

Parameters:filename
Returns:Video’s public URL
storage.upload_data(data: _io.BytesIO, content_type: str, full_path: pathlib.Path) → str[source]

Uploads binary data to the given path on Google Cloud Storage.

Parameters:
  • data – Binary data (for now just photos/videos).
  • content_type – Correct content type for the data we’re uploading.
  • full_path – Full path including bucket.
Raises:

ValueError – If full_path begins with a leading slash.

Returns:

Public URL to access file.