chris chris - 7 months ago 37
Python Question

way to convert image straight from url to base64 without saving as a file python

I'm looking to convert a web-based image to base64. I know how to do it currently by saving the image as a .jpg file and then using the base64 library to convert the .jpg file to a base64 string.

I'm wondering whether I could skip out the step of saving the image first?



Using the requests library:

import base64

import requests

def get_as_base64(url):
    return base64.b64encode(requests.get(url).content))