【发布时间】:2014-07-10 10:47:31
【问题描述】:
我正在尝试从 Go 服务器端代码中读取 Blobstore 中的图像。但是如果图像很大(例如:0.5MB - 1.7MB),字节缓冲区的很大一部分会变为 0,这会破坏图像。
如果我使用serveUrl,图像可以工作,但在这种情况下,这对我来说不是一个选项。
我的第一个想法是读取有大小限制,found this:
除了系统范围的安全配额外,还有一个特别适用的限制 对 Blobstore 的使用:Blobstore 数据的最大大小 应用程序通过一次 API 调用可以读取的大小为 32 兆字节。
我阅读的图片远不及 32MB。
我用来从 Blobstore 读取的函数:
func BlobAsBase64(c appengine.Context, blobKey string) (*blobstore.BlobInfo, string, error) {
info, err := blobstore.Stat(c, appengine.BlobKey(blobKey))
if err != nil {
return nil, "", err
}
imageBuffer := make([]byte, info.Size)
reader := blobstore.NewReader(c, appengine.BlobKey(blobKey))
if _, err = reader.Read(imageBuffer); err != nil {
return nil, "", err
}
imageBase64 := base64.StdEncoding.EncodeToString(imageBuffer)
return info, imageBase64, nil
}
当我从 Blobstore 读取图像时,我的图像损坏的原因是什么?
【问题讨论】:
标签: google-app-engine go blobstore