【发布时间】:2020-09-13 17:44:10
【问题描述】:
我正在这样做并且工作得很好:
def b64_image(filename):
with open("static/img/"+filename, 'rb') as f:
b64 = base64.b64encode(f.read())
return b64.decode('utf-8')
但现在我将图像上传到 S3 存储桶,所以我编辑了代码:
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')
我收到以下错误:
FileNotFoundError: [Errno 2] No such file or directory:
我怎样才能使这段代码工作?如何使代码查找实际的 URL 图像?提前致谢。
【问题讨论】:
-
您需要使用 boto3 来访问 S3 上的文件。你看过吗?
标签: python image amazon-web-services file