I have a bytes object which is actually the file in the format of dataurl
. It is about 500 KB.
I need to drop 37 bytes of header (I made it using a slice) and replace %3D
by =
at the end of the file (this sequence can be found 0-2 times).
Urllib.parse
changes all entries in the object.
Is there a beautiful way to process this object?
content_length = int(self.headers['Content-Length']) # <--- Gets the size of data
post_body = self.rfile.read(content_length) # <--- Gets the data itself
print(len(post_body))
with open("1111", "wb") as fd:
fd.write(post_body)
post_body = post_body[37:len(post_body)]
with open("decoded.png", "wb") as fh:
fh.write(base64.decodebytes(post_body))
In the last line, I have a problem.
=
characters might be added to make the last block contain four base64 characters. But in the post request, I have %3D
instead of =
.