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
¶
Get metadata of a file from a URL or file path.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Dictionary containing metadata |
image_to_base64
¶
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
¶
Validate a Base64 encoded string.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the string is a valid Base64 encoded string, False otherwise |
get_hash
¶
Generate SHA-1 hash for the given data.
| RETURNS | DESCRIPTION |
|---|---|
str
|
SHA-1 hash of the data |