Backend Codes & Tools
Sending Files in Base64
import base64
def file_to_base64(file_path):
with open(file_path, "rb") as file:
base64_encoded = base64.b64encode(file.read()).decode("utf-8")
return base64_encoded
# Example usage
file_path = "bill-gates.pdf" # Change this to your file path
base64_string = file_to_base64(file_path)
print(base64_string)
Last updated