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:

URL = ...

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

    r =, 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?