谷歌存储BlobKeyForFile错误

Im trying to serve images from google storage via google images

In order to do that i need to create blob key.

i tried several ways togenerate the key but got errors

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. What is the correct path ?
  2. Dose the images cached and behind cdn ?

I got this error as well (among others) and here are the fixes which worked for me:

  1. When saving the file to Google Cloud Storage you need to make it public like so: writer.ACL = []storage.ACLRule{{Entity: storage.AllUsers, Role: storage.RoleReader}}
  2. The correct path is fmt.Sprintf("/gs/%s/%s", bucketName, objectName) where objectName is the path to the file within the bucket.
  3. You have to make the bucket public. How to do that is described in here.