blob.download_as_string() return 是什么编码?

What encoding does blob.download_as_string() return?

我正在从 Google 存储中下载一个字节字符串文件,对其进行 b64 编码,并将其用作 Google Vision API.

的输入
storage_client = storage.Client(project=[PROJECT])
bucket = storage_client.get_bucket([BUCKET])
blob = bucket.blob([KEY])

content = blob.download_as_string()
b64content = base64.b64encode(content)

client = vision.ImageAnnotatorClient()
image = vision.types.Image(content=b64content)

我在使用 b64 内容时遇到错误图像。但是,如果我使用非 base64 内容,我对 Vision API 的调用会成功:

image = vision.types.Image(content=content)

blob.download_as_string() return 是一个已经经过 base64 编码的字节串吗?

简答:不,它不是 base64 编码的。那为什么它与非编码字符串一起使用?

像您一样使用 Python 客户端,您不需要对字符串进行编码,如 here. You need to encode it if you post a Vision API request in JSON, like this one 所示。这就是为什么你在没有 base64.b64encode().

的情况下已经可以工作的原因