0

I was doing this and worked perfectly fine:

def b64_image(filename):
    with open("static/img/"+filename, 'rb') as f:
        b64 = base64.b64encode(f.read())
        return b64.decode('utf-8')

But now I uploaded the images to an S3 Bucket so I edited the code:

def b64_image(filename):
    with open("https://mybucket.s3-sa-east-1.amazonaws.com/" + filename, 'rb') as f:
        b64 = base64.b64encode(f.read())
        return b64.decode('utf-8')

And I'm getting the fllowing error:

FileNotFoundError: [Errno 2] No such file or directory:

How can I make this code work? How can I make the code to look for the actual URL image? Thanks in advance.

1 Answers1

0

In order to use open on files in S3 you will need to use a 3rd party library. In particular, this maintained and active library, smart-open does just that.

gold_cy
  • 13,648
  • 3
  • 23
  • 45