Skip to content

File Operations

Type detection, metadata extraction, and image processing.


get_file_type

Python
get_file_type(file_source: Union[str, Path, bytes, BytesIO, StreamingBody], is_url: bool = True) -> Tuple[str, str]

Determine the file type of a file from a URL, file path, Base64 string, bytes, or BytesIO.

RETURNS DESCRIPTION
Tuple[str, str]

File type based on extension or MIME type

get_metadata

Python
get_metadata(file_source, is_url=True)

Get metadata of a file from a URL or file path.

RETURNS DESCRIPTION
dict

Dictionary containing metadata

image_to_base64

Python
image_to_base64(image_source, is_url=True, return_hash=False)

Convert an image from a URL or file path to a Base64 string, optionally returning its SHA-1 hash.

RETURNS DESCRIPTION
str | tuple(str, str)

Base64 encoded string of the image and optionally the SHA-1 hash in order

validate_base64

Python
validate_base64(b64_string)

Validate a Base64 encoded string.

RETURNS DESCRIPTION
bool

True if the string is a valid Base64 encoded string, False otherwise

get_hash

Python
get_hash(data)

Generate SHA-1 hash for the given data.

RETURNS DESCRIPTION
str

SHA-1 hash of the data