How to upload the image with it's encoding binary data?

I have the ASCII characters of a image binary data and can upload this image to some URL use the code below:

ASCII_CHARACTERS = ......
URL = ...

with open('z.jpg','wb+') as f:

    f.write(base64.b64decode(ASCII_CHARACTERS))
    f.seek(0)
    r = requests.post(URL, files={'media':f})

This code is workable but have to write this image to disk first. Can I fix this code and upload it without writing step?

Thanks.