ServingURL returns a URL that will serve an image from Blobstore.
(c context.Context, key appengine.BlobKey, opts *ServingURLOptions)
| 28 | |
| 29 | // ServingURL returns a URL that will serve an image from Blobstore. |
| 30 | func ServingURL(c context.Context, key appengine.BlobKey, opts *ServingURLOptions) (*url.URL, error) { |
| 31 | req := &pb.ImagesGetUrlBaseRequest{ |
| 32 | BlobKey: (*string)(&key), |
| 33 | } |
| 34 | if opts != nil && opts.Secure { |
| 35 | req.CreateSecureUrl = &opts.Secure |
| 36 | } |
| 37 | res := &pb.ImagesGetUrlBaseResponse{} |
| 38 | if err := internal.Call(c, "images", "GetUrlBase", req, res); err != nil { |
| 39 | return nil, err |
| 40 | } |
| 41 | |
| 42 | // The URL may have suffixes added to dynamically resize or crop: |
| 43 | // - adding "=s32" will serve the image resized to 32 pixels, preserving the aspect ratio. |
| 44 | // - adding "=s32-c" is the same as "=s32" except it will be cropped. |
| 45 | u := *res.Url |
| 46 | if opts != nil && opts.Size > 0 { |
| 47 | u += fmt.Sprintf("=s%d", opts.Size) |
| 48 | if opts.Crop { |
| 49 | u += "-c" |
| 50 | } |
| 51 | } |
| 52 | return url.Parse(u) |
| 53 | } |
| 54 | |
| 55 | // DeleteServingURL deletes the serving URL for an image. |
| 56 | func DeleteServingURL(c context.Context, key appengine.BlobKey) error { |
nothing calls this directly
no test coverage detected
searching dependent graphs…