import "github.com/ospry/ospry-go"
Package ospry provides bindings for ospry's image hosting api (see https://ospry.io).
If you're writing a web service, images will generally be uploaded directly to ospry from the browser via ospry.js (with your public key), but you'll keep track of them server-side. Server-side operations should be done with your secret key:
ospry.SetKey("sk-test-********")
If you've turned the claiming feature on in your account settings (recommended), then you'll need to claim the images after your client uploads them and sends the resulting ids to your server:
metadata, err := ospry.Claim(id)
Once you have claimed the images, you can retrieve their metadata, change their permissions and delete them as needed.
metadata, err := ospry.GetMetadata(id) metadata, err := ospry.MakePrivate(id) metadata, err := ospry.MakePublic(id) err := ospry.Delete(id)
To give access to private images to someone that doesn't have your secret key (i.e your js client running in the browser), you can use FormatURL to sign the urls by providing an expiration time.
url, err := ospry.FormatURL(image.URL, &RenderOpts{ TimeExpired: time.Now().Add(5*time.Minute), })
Image data can be uploaded and downloaded server-side too if you want:
metadata, err := ospry.UploadPublic("foo.jpg", fooReader) metadata, err := ospry.UploadPrivate("bar.jpg", barReader) readCloser, err := ospry.Download(metadata.URL, &RenderOpts{MaxHeight: 400})
Remember to close any ReadClosers you get from Download once you're done reading.
Delete calls Delete on the default client.
func Download(url string, opts *RenderOpts) (io.ReadCloser, error)
Download calls Download on the default client.
func FormatURL(urlstr string, opts *RenderOpts) (string, error)
FormatURL calls FormatURL on the default client.
SetKey changes the api key used by the default client.
A Client performs authenticated API calls.
New creates a client that authenticates with the given key. By default, the client's HTTPClient is http.DefaultClient.
Claim claims ownership of an image that was uploaded client-side. You need to claim images to prevent them from disappearing (if you've turned claiming on in your account settings).
Delete deletes an image. Attempts to retrieve images that have been deleted will result in 404s.
func (c *Client) Download(urlstr string, opts *RenderOpts) (io.ReadCloser, error)
Download retrieves the image data at the given url. You can render a modified image by providing a non-nil RenderOpts.
FormatURL modifies an image url to produce a url that can be used to download a modified image (e.g. resized). If TimeExpired is given, the url is signed with the client's key and can be used to download access a private image until TimeExpired has past. An error is returned if the given url is invalid.
GetMetadata retrieves the metadata for the image with the given id.
MakePrivate makes an image an private if it isn't already. Private images can be downloaded by anyone who has an unexpired, signed url to that image (see FormatURL).
MakePublic makes an image public if it isn't already. Public images can be downloaded by anyone who has the url to that image.
UploadPrivate uploads a private image with the given filename. The image will be automatically claimed if the client was initialized with your secret key.
UploadPublic uploads a public image with the given filename. The image will be automatically claimed if the client was initialized with your secret key.
type Error struct { HTTPStatusCode int `json:"httpStatusCode"` Cause string `json:"cause"` Message string `json:"message"` }
type Metadata struct { ID string `json:"id"` URL string `json:"url"` HTTPSURL string `json:"httpsURL"` TimeCreated time.Time `json:"timeCreated"` IsClaimed bool `json:"isClaimed"` IsPrivate bool `json:"isPrivate"` Filename string `json:"filename"` Format string `json:"format"` Size int64 `json:"size"` Height int `json:"height"` Width int `json:"width"` }
Claim calls Claim on the default client.
GetMetadata calls GetMetadata on the default client.
MakePrivate calls MakePrivate on the default client.
MakePublic calls MakePublic on the default client.
UploadPrivate calls UploadPrivate on the default client.
UploadPublic calls UploadPublic on the default client.
Path | Synopsis |
---|---|
example |
Package ospry imports 11 packages (graph) and is imported by 1 packages. Updated 2016-07-19. Refresh now. Tools for package owners.