Hi, I'm not sure what I'm doing wrong here. I'm using appengine.NewContext(r) to make a new context, yet when I try to call blobstore.BlobKeyForFile with the context it panics with "not an App Engine context". It doesn't work with dev_appserver.py nor when deploying as an app engine service. Does someone know what I can try out?
I should note that I'm a golang noob; I just installed it via homebrew today, so not sure if there is something I have to do in my environment.
package main
import (
"fmt"
"log"
"net/http"
"encoding/json"
"google.golang.org/appengine"
"google.golang.org/appengine/blobstore"
)
type Image struct {
Bucket string
Path string
}
func main() {
http.HandleFunc("/serveurl", handle)
log.Print("Listening on port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
func handle(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
image := Image{}
err := json.NewDecoder(r.Body).Decode(&image)
if err != nil{
panic(err)
}
fullPath := fmt.Sprintf("/gs/%s", image.Bucket, image.Path)
fmt.Fprint(w, fullPath)
key, err := blobstore.BlobKeyForFile(ctx, fullPath)
if err != nil {
panic(err)
}
fmt.Fprint(w, key)
}