关于post:为什么在服务器端将base64字符串作为参数发送后更改了长度,所以更改了长度?

Why base64 string sent as param changing length after decoding it on server side?

在客户端,我正在读取图像文件并将其编码为base64,并将其作为URL参数发送给

1
2
3
4
5
img = open("file.png","rb").read()
print len(img)
img = img.encode("base64")
print len(img)
print len(img.decode("base64"))

打印252235340742252235

在服务器端解码接收到的str无法产生相同的结果。我将编码后的base64发布为" http://url.com/test?image = img_str "。

1
2
3
4
img = flask.request.args["image"]
print len(img)
img = img.decode("base64")
print len(img)

打印340742非常好,而248176应该实际上是原始长度。发布请求期间是否修改了图像参数?如何在不使用请求或任何其他解决方案中的文件参数的情况下执行此操作。


所以,我想通了!

在将编码后的字符串作为URL参数发送时,字符串中的""将转换为""。因此,在解码之前必须encoded_base64.replace("","+")。而且行得通!