【问题标题】:google storage BlobKeyForFile error谷歌存储 BlobKeyForFile 错误
【发布时间】:2016-10-02 13:25:43
【问题描述】:

我正在尝试通过谷歌images从谷歌存储中提供图片

为此,我需要创建 blob 密钥。

我尝试了几种方法来生成密钥,但出现错误

loc := fmt.Sprintf("/gs/%s/%s", BUCKET, s)
applog.Infof(appCtx, "%s", loc)
bkey, err := blobstore.BlobKeyForFile(appCtx, loc)
if err != nil {
    gc.JSON(500, model.GenericResponse{500, err.Error()})
    return
}
opt := &image.ServingURLOptions{}
u, err := image.ServingURL(appCtx, bkey, opt)
if err != nil {
    gc.JSON(500, model.GenericResponse{500, err.Error()})
    return
}

// i tried with file extension to 
/gs/bucktname/CXlvJUKiTmo9joe6
OBJECT_NOT_FOUND 

gs://bucktname/rUAJOYKQbORzOYvs
"description": "API error 6 (images: INVALID_BLOB_KEY)"

gs:/bucktname/MlY77iFNbBca2KCA
"description": "API error 6 (images: INVALID_BLOB_KEY)"
  1. 正确的路径是什么?
  2. dose 缓存和cdn 后面的图像?

【问题讨论】:

  • 我现在也有同样的问题。你找到答案了吗?令人困惑的是,它在本地模拟的 appengine 上运行时可以工作,但在实际中却失败了。

标签: google-app-engine go google-cloud-storage


【解决方案1】:

我也遇到了这个错误(以及其他错误),以下是对我有用的修复:

  1. 将文件保存到 Google Cloud Storage 时,您需要将其公开,如下所示:writer.ACL = []storage.ACLRule{{Entity: storage.AllUsers, Role: storage.RoleReader}}
  2. 正确的路径是fmt.Sprintf("/gs/%s/%s", bucketName, objectName),其中objectName 是存储桶中文件的路径。
  3. 您必须公开存储桶。 here 中描述了如何做到这一点。

【讨论】:

    猜你喜欢
    • 2017-02-10
    • 2018-07-22
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 2016-10-25
    • 2019-11-28
    • 1970-01-01
    相关资源
    最近更新 更多