本文整理匯總了Golang中appengine/image.ServingURL函數的典型用法代碼示例。如果您正苦於以下問題:Golang ServingURL函數的具體用法?Golang ServingURL怎麽用?Golang ServingURL使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ServingURL函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getImageUrl
func getImageUrl(c appengine.Context, key appengine.BlobKey) (*url.URL, error) {
// get image url only if it was specified
option := image.ServingURLOptions{
Secure: true, // serve on https
}
return image.ServingURL(c, key, &option)
}
示例2: CropImage
func (c Creature) CropImage(width, height, max int, ctx appengine.Context) (image.Image, error) {
url, _ := aeimg.ServingURL(ctx, c.BlobKey, &aeimg.ServingURLOptions{Size: max, Crop: true})
client := urlfetch.Client(ctx)
resp, _ := client.Get(url.String())
// Just in case
if resp.StatusCode != 200 {
return nil, errors.New("Blob not found")
}
// Do we need further cropping?
if width == height {
return jpeg.Decode(resp.Body)
}
src, err := jpeg.Decode(resp.Body)
dest := image.NewRGBA(image.Rect(0, 0, width, height))
if err != nil {
return nil, err
}
graphics.Thumbnail(dest, src)
return dest, nil
}
示例3: handleConfirmItemEntry
func handleConfirmItemEntry(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
q := datastore.NewQuery("lighting").Order("-CreationTime").Limit(1)
confirm := &ResultRead{}
//set up an infinite loop - it will break when "Done"
for t := q.Run(c); ; {
var x ResultData
_, err := t.Next(&x)
if err == datastore.Done {
break
}
if err != nil {
serveError(c, w, err)
return
}
//Do something with the iterator
url, err := image.ServingURL(c, x.MainPhoto, nil)
if err != nil {
serveError(c, w, err)
return
}
confirm.Manufacturer = x.Manufacturer
confirm.URL = template.HTML(url.String())
}
w.Header().Set("Content-Type", "text/html")
err := confirmItemEntryTemplate.Execute(w, confirm)
if err != nil {
serveError(c, w, err)
return
}
}
示例4: handleLast10
func handleLast10(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
q := datastore.NewQuery("lighting").Order("-CreationTime").Limit(10)
confirm := &ResultRead{}
b := make(map[int]ResultRead)
for t, i := q.Run(c), 0; ; i++ {
var x ResultData
_, err := t.Next(&x)
if err == datastore.Done {
break
}
if err != nil {
serveError(c, w, err)
return
}
url, err := image.ServingURL(c, x.MainPhoto, nil)
if err != nil {
serveError(c, w, err)
return
}
confirm.Manufacturer = x.Manufacturer
confirm.URL = template.HTML(url.String())
b[i] = *confirm
}
w.Header().Set("Content-Type", "text/html")
err := last10Template.Execute(w, b)
if err != nil {
serveError(c, w, err)
return
}
}
示例5: CreateUrls
func (fi *FileInfo) CreateUrls(r *http.Request, c appengine.Context) {
u := &url.URL{
Scheme: r.URL.Scheme,
Host: appengine.DefaultVersionHostname(c),
Path: "/",
}
uString := u.String()
fi.Url = uString + escape(string(fi.Key)) + "/" +
escape(string(fi.Name))
fi.DeleteUrl = fi.Url + "?delete=true"
fi.DeleteType = "DELETE"
if imageTypes.MatchString(fi.Type) {
servingUrl, err := image.ServingURL(
c,
fi.Key,
&image.ServingURLOptions{
Secure: strings.HasSuffix(u.Scheme, "s"),
Size: 0,
Crop: false,
},
)
check(err)
fi.ThumbnailUrl = servingUrl.String() + THUMBNAIL_PARAM
}
}
示例6: loadImage
func loadImage(c appengine.Context, f *Feed) string {
s := f.Link
if s == "" {
s = f.Url
}
u, err := url.Parse(s)
if err != nil {
return ""
}
u.Path = "/favicon.ico"
u.RawQuery = ""
u.Fragment = ""
g := goon.FromContext(c)
i := &Image{Id: u.String()}
if err := g.Get(i); err == nil {
return i.Url
}
client := urlfetch.Client(c)
r, err := client.Get(u.String())
if err != nil || r.StatusCode != http.StatusOK || r.ContentLength == 0 {
return ""
}
b, err := ioutil.ReadAll(r.Body)
r.Body.Close()
if err != nil {
return ""
}
buf := bytes.NewBuffer(b)
_, t, err := image.DecodeConfig(buf)
if err != nil {
t = "application/octet-stream"
} else {
t = "image/" + t
}
w, err := blobstore.Create(c, t)
if err != nil {
return ""
}
if _, err := w.Write(b); err != nil {
return ""
}
if w.Close() != nil {
return ""
}
i.Blob, _ = w.Key()
su, err := aimage.ServingURL(c, i.Blob, &aimage.ServingURLOptions{Size: 16})
if err != nil {
if err = blobstore.Delete(c, i.Blob); err != nil {
c.Errorf("blob delete err: %v", err)
}
return ""
}
i.Url = su.String()
g.Put(i)
return i.Url
}
示例7: UpdateServingLogoUrl
func UpdateServingLogoUrl(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
const batch = 50
page, _ := strconv.Atoi(r.FormValue("pg"))
if page < 1 {
page = 1
}
offset := batch * (page - 1)
q := datastore.NewQuery("EmpLogo").Offset(offset).Order("IdEmp").Limit(batch)
n, _ := q.Count(c)
for i := q.Run(c); ; {
var e model.Image
key, err := i.Next(&e)
if err == datastore.Done {
break
}
// Se crea la URL para servir la oferta desde el CDN, si no se puede
// se deja en blanco
var imgprops image.ServingURLOptions
imgprops.Secure = true
imgprops.Size = 180
imgprops.Crop = false
if e.Sp4 == "" && e.IdEmp != "" {
var blobkey appengine.BlobKey
blob, err := blobstore.Create(c, "image/jpeg")
if err != nil {
c.Errorf("blobstore Create: %v", e.IdEmp)
}
_, err = blob.Write(e.Data)
if err != nil {
c.Errorf("blobstore Write: %v", e.IdEmp)
}
err = blob.Close()
if err != nil {
c.Errorf("blobstore Close: %v", e.IdEmp)
}
blobkey, err = blob.Key()
if err != nil {
c.Errorf("blobstore Key Gen: %v", e.IdEmp)
}
if url, err := image.ServingURL(c, blobkey, &imgprops); err != nil {
c.Errorf("Cannot construct EmpLogo ServingURL : %v", e.IdEmp)
} else {
e.Sp3 = string(blobkey)
e.Sp4 = url.String()
}
_, err = datastore.Put(c, key, &e)
if err != nil {
c.Errorf("PutEmpLogo(); Error al intentar actualizar Emplogo : %v", e.IdEmp)
}
}
}
c.Infof("UpdateServingLogoUrl() Pagina: %d, actualizados: %d, del %d al %d", page, n, offset, offset+n)
return
}
示例8: handleServeImg
func handleServeImg(w http.ResponseWriter, r *http.Request) {
if r.FormValue("id") != "none" {
c := appengine.NewContext(r)
var imgprops image.ServingURLOptions
imgprops.Secure = true
imgprops.Size = 400
imgprops.Crop = false
url, _ := image.ServingURL(c, appengine.BlobKey(r.FormValue("id")), &imgprops)
http.Redirect(w, r, url.String(), http.StatusFound)
}
return
}
示例9: serveThumb
func serveThumb(c appengine.Context, w http.ResponseWriter, r *http.Request) {
// c := appengine.NewContext(r)
k := appengine.BlobKey(r.FormValue("blobkey"))
var o image.ServingURLOptions = *new(image.ServingURLOptions)
o.Size = 200
o.Crop = true
url, err := image.ServingURL(c, k, &o)
util_err.Err_http(w, r, err, false)
http.Redirect(w, r, url.String(), http.StatusFound)
}
示例10: GetServingURL
// GCSに保存された畫像の公開URLを取得します。
func GetServingURL(c appengine.Context, filename string) (servingURL *url.URL, err error) {
blobKey, err := blobstore.BlobKeyForFile(c, filename)
if err != nil {
c.Errorf("serve.go:14: %s", err.Error())
return nil, err
}
opts := &image.ServingURLOptions{Secure: true}
servingURL, err = image.ServingURL(c, blobKey, opts)
if err != nil {
c.Errorf("serve.go:25: %s", err.Error())
return nil, err
}
return servingURL, nil
}
示例11: images2urls
func (m *Message) images2urls(c appengine.Context) {
urlc := make(chan string)
for _, im := range m.images {
go func(img *img_attachment) {
w, err := blobstore.Create(c, img.Type)
if err != nil {
urlc <- err.Error()
return
}
_, err = w.Write(img.Data)
if err != nil {
urlc <- err.Error()
return
}
err = w.Close()
if err != nil {
urlc <- err.Error()
return
}
key, err := w.Key()
if err != nil {
urlc <- err.Error()
return
}
url, err := image.ServingURL(c, key, &image.ServingURLOptions{Secure: false, Size: 0, Crop: false})
if err != nil {
urlc <- err.Error()
return
}
urlc <- url.String()
}(&im)
}
imagescnt := len(m.images)
m.ImageUrls = make([]string, 0, imagescnt)
for i := 0; i < imagescnt; i++ {
u := <-urlc
if strings.HasPrefix(u, "http") {
m.ImageUrls = append(m.ImageUrls, u)
} else {
c.Errorf("Error converting image to url: %v", u)
}
}
return
}
示例12: fetch
func fetch(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
imageUrl := r.FormValue("image")
c.Infof("THIS IS IMAGE URL %v", imageUrl)
client := urlfetch.Client(c)
resp, err := client.Get(imageUrl)
if error3(err, c, w) {
return
}
blob, err := blobstore.Create(c, resp.Header.Get("Content-Type"))
if error3(err, c, w) {
return
}
written, err := io.Copy(blob, resp.Body)
if error3(err, c, w) {
return
}
if written < 100 {
c.Infof("image is too small %v", written)
return
}
err = blob.Close()
if error3(err, c, w) {
return
}
blobkey, err := blob.Key()
if error3(err, c, w) {
return
}
thumbnailUrl, err := image.ServingURL(c, blobkey, &image.ServingURLOptions{Size: 100})
if error3(err, c, w) {
return
}
t := thumbnailUrl.String()
errr := channel.Send(c, "qwerty", t)
if error3(errr, c, w) {
return
}
// c.Infof("THIS IS IMAGE URL %v", t)
}
示例13: api_imageLinkObject
// Get the image link for an object.
func api_imageLinkObject(w http.ResponseWriter, r *http.Request) {
// We use the blob store + images to generate a serving url for the file
c := appengine.NewContext(r)
vars := mux.Vars(r)
bk, err := blobstore.BlobKeyForFile(c, "/gs/"+bucketName+"/"+vars["key"])
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if imageUrl, err := image.ServingURL(c, bk, nil); err == nil {
fmt.Fprint(w, imageUrl)
} else {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
示例14: UpdateServingUrl
func UpdateServingUrl(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
const batch = 300
page, _ := strconv.Atoi(r.FormValue("pg"))
if page < 1 {
page = 1
}
offset := batch * (page - 1)
q := datastore.NewQuery("Oferta").Offset(offset).Order("-FechaHora").Limit(batch)
n, _ := q.Count(c)
for i := q.Run(c); ; {
var e model.Oferta
key, err := i.Next(&e)
if err == datastore.Done {
break
}
// Se crea la URL para servir la oferta desde el CDN, si no se puede
// se deja en blanco
var imgprops image.ServingURLOptions
imgprops.Secure = true
imgprops.Size = 400
imgprops.Crop = false
if e.BlobKey != "none" && e.Codigo == "" {
if url, err := image.ServingURL(c, e.BlobKey, &imgprops); err != nil {
c.Errorf("Cannot construct ServingURL : %v", e.IdOft)
e.Codigo = ""
} else {
e.Codigo = url.String()
}
//c.Errorf("Get Cta Key; Error al intentar leer key.Parent() de Empresa : %v", e.IdEmp)
_, err = datastore.Put(c, key, &e)
if err != nil {
c.Errorf("PutEmpresa(); Error al intentar actualizar empresa : %v", e.IdEmp)
}
}
}
c.Infof("UpdateServingUrl() Pagina: %d, actualizados: %d, del %d al %d", page, n, offset, offset+n)
return
}
示例15: handleUpload
func handleUpload(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
blobs, other, err := blobstore.ParseUpload(r)
if err != nil {
serveError(c, w, err)
return
}
mainPhoto := blobs["mainPhoto"][0].BlobKey
creationTime := blobs["mainPhoto"][0].CreationTime
result := ResultData{
Manufacturer: other["manufacturer"][0],
MainPhoto: mainPhoto,
CreationTime: creationTime,
}
key, err := datastore.Put(c, datastore.NewIncompleteKey(c, "lighting", nil), &result)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var result2 ResultData
if err = datastore.Get(c, key, &result2); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/html")
url, err := image.ServingURL(c, result2.MainPhoto, nil)
if err != nil {
serveError(c, w, err)
return
}
toPass := &ResultRead2{result2, template.HTML(url.String())}
w.Header().Set("Content-Type", "text/html")
err = uploadTemplate.Execute(w, toPass)
if err != nil {
serveError(c, w, err)
return
}
}