Boto3:将文件从base64上传到S3 [英] Boto3: upload file from base64 to S3
问题描述
如何使用boto3将base64编码的文件直接上传到S3?
How can I directly upload a base64 encoded file to S3 with boto3?
object = s3.Object(BUCKET_NAME,email+"/"+save_name)
object.put(Body=base64.b64decode(file))
我试图像这样上载base64编码的文件,但随后该文件损坏了.直接上传字符串而不进行base64解码也不起作用.
I tried to upload the base64 encoded file like this, but then the file is broken. Directly uploading the string without the base64 decoding also doesn't work.
是否有与boto2中的set_contents_from_string()
类似的东西?
Is there anything similar to set_contents_from_string()
from boto2?
推荐答案
我刚刚解决了问题,发现上传方式正确,但是base64字符串不正确,因为它仍然包含前缀data:image/jpeg;base64,
-删除该前缀解决了问题.
I just fixed the problem and found out that the way of uploading was correct, but the base64 string was incorrect because it still contained the prefix data:image/jpeg;base64,
- removing that prefix solved the problem.
这篇关于Boto3:将文件从base64上传到S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!