bedrock.helpers.files
1import base64 # pragma: integration 2import os # pragma: integration 3from bedrock.log import log_config # pragma: integration 4 5log = log_config("files") # pragma: integration 6 7 8def base64_to_file(file_path: str, base64_string: str) -> str: # pragma: integration 9 """ 10 Turns a base64 string into a file saved into `file_path`. 11 :param file_path: 12 :param base64_string: 13 :return: 14 """ 15 with open(file_path, "wb") as fh: 16 fh.write(base64.b64decode(base64_string)) 17 if os.path.isfile(file_path): 18 return file_path 19 log.error(f"Unable to create file {file_path} from provided base64 string.") 20 log.debug(f"Base64 string: {base64_string}") 21 raise Exception("Unable to create file from base64 string.")
log =
<MyLogger BEDROCK-files (INFO)>
def
base64_to_file(file_path: str, base64_string: str) -> str:
9def base64_to_file(file_path: str, base64_string: str) -> str: # pragma: integration 10 """ 11 Turns a base64 string into a file saved into `file_path`. 12 :param file_path: 13 :param base64_string: 14 :return: 15 """ 16 with open(file_path, "wb") as fh: 17 fh.write(base64.b64decode(base64_string)) 18 if os.path.isfile(file_path): 19 return file_path 20 log.error(f"Unable to create file {file_path} from provided base64 string.") 21 log.debug(f"Base64 string: {base64_string}") 22 raise Exception("Unable to create file from base64 string.")
Turns a base64 string into a file saved into file_path.
Parameters
- file_path:
- base64_string: