download_url.py
Source: sunholo/gcs/download_url.py
Functions
construct_download_link(source_uri: 'str') -> 'Tuple[str, str, bool]'
Creates a viewable Cloud Storage web browser link from a gs:// URI.
get_bytes_from_gcs(gs_uri) -> 'Optional[bytes]'
Downloads a file from Google Cloud Storage and returns its bytes.
Args: gs_uri (str): The Google Cloud Storage URI of the file to download (e.g., 'gs://bucket_name/file_name').
Returns: bytes: The content of the file in bytes, or None if an error occurs.
get_image_from_gcs(gs_uri: 'str') -> 'Image.Image'
Converts image bytes from GCS to a PIL Image object.
construct_download_link_simple(bucket_name: 'str', object_name: 'str') -> 'Tuple[str, str, bool]'
Creates a viewable Cloud Storage web browser link from a gs:// URI.
Args: source_uri: The gs:// URI of the object in Cloud Storage.
Returns: A URL that directly access the object in the Cloud Storage web browser.
get_bucket(bucket_name: 'str') -> 'Optional[Bucket]'
Gets a Cloud Storage bucket and initialised GCS client
Args: bucket_name: Name of the bucket
Returns:
parse_gs_uri(gs_uri: 'str') -> 'Tuple[str, str]'
Parses a gs:// URI into the bucket name and object name.
Args: gs_uri: The gs:// URI to parse.
Returns: A tuple containing the bucket name and object name.
sign_gcs_url(bucket_name: 'str', object_name: 'str', expiry_secs: 'int' = 86400) -> 'Optional[str]'
Creates a signed URL so that users can download a file from Google Cloud Storage without authentication
Args: bucket_name: Name of the bucket where the object lies object_name: Object within the bucket expiry_secs: How long the link will be valid - default 24hrs
Returns: str: The signed URL or None if not avialable