Skip to content

Instantly share code, notes, and snippets.

@maniartech
Created November 10, 2012 15:15
Show Gist options
  • Save maniartech/4051374 to your computer and use it in GitHub Desktop.
Save maniartech/4051374 to your computer and use it in GitHub Desktop.
A python function which converts file to base64 string.
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