func Save(rw http.ResponseWriter, req *http.Request, r render.Render, params martini.Params) { ctx := appengine.NewContext(req) blobs, vals, err := blobstore.ParseUpload(req) if err != nil { http.Redirect(rw, req, "/admin/banners/"+params["id"]+"?error="+err.Error(), http.StatusFound) return } var title string var caption string if len(vals["title"]) > 0 { title = vals["title"][0] } if len(vals["caption"]) > 0 { caption = vals["caption"][0] } b := banner.Banner{} intID, err := strconv.Atoi(params["id"]) if err == nil { b.ID = int64(intID) } b.Get(ctx) b.Title = title b.Caption = caption file := blobs["image"] if len(file) != 0 { b.Image = fmt.Sprintf("/blob/%s", string(file[0].BlobKey)) } else if intID == 0 { http.Redirect(rw, req, "/admin/banners/"+params["id"]+"?error=You must upload an image", http.StatusFound) return } err = b.Save(ctx) if err != nil { http.Redirect(rw, req, "/admin/banners/"+params["id"]+"?error="+err.Error(), http.StatusFound) return } http.Redirect(rw, req, "/admin/banners/"+strconv.Itoa(int(b.ID))+"?success=Banner saved", http.StatusFound) return }