-
-
Save allanaguilar/b9001715c09ba4747a11bbc2431c1aba to your computer and use it in GitHub Desktop.
A python function which converts file to base64 string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def file_to_base64(file_path): | |
""" | |
A simple function which accepts the file_path and | |
converts and returns base64 string if specified file | |
exists. Returns blank string '' if file is not found. | |
""" | |
from os import path | |
if not path.exists(file_path): | |
return '' | |
return open(file_path, 'rb').read().encode('base64') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment