I have to upload a tar ball (tar.gz) file into s3 but by calling internal API.
The API accepts base64 encoded string.
Is there a way to convert tar.gz file to bytes string and then convert to base64 string in python?
To read a file as a byte stream is pretty straightforward:
with open(filename,"rb") as f:
data = f.read()
The extra "b" is for "binary mode"
Converting that into base64 is also simple, you only need to use the handy base64
module.:
import base64
data = base64.b64encode(data)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.