Documentation ¶
Overview ¶
Package cloudinary provides support for managing static assets on the Cloudinary service.
The Cloudinary service allows image and raw files management in the cloud.
Index ¶
- func EnsureTrailingSlash(dirname string) string
- type Derived
- type Resource
- type ResourceDetails
- type ResourceType
- type Service
- func (s *Service) ApiKey() string
- func (s *Service) CloudName() string
- func (s *Service) DefaultUploadURI() *url.URL
- func (s *Service) Delete(publicId, prepend string, rtype ResourceType) error
- func (s *Service) DropAll(w io.Writer) error
- func (s *Service) DropAllImages(w io.Writer) error
- func (s *Service) DropAllRaws(w io.Writer) error
- func (s *Service) KeepFiles(pattern string) error
- func (s *Service) Rename(publicID, toPublicID, prepend string, rtype ResourceType) error
- func (s *Service) ResourceDetails(publicId string) (*ResourceDetails, error)
- func (s *Service) Resources(rtype ResourceType) ([]*Resource, error)
- func (s *Service) Simulate(v bool)
- func (s *Service) Upload(path string, data io.Reader, prepend string, randomPublicId bool, ...) (string, error)
- func (s *Service) UploadImage(path string, data io.Reader, prepend string) (string, error)
- func (s *Service) UploadPdf(path string, data io.Reader, prepend string) (string, error)
- func (s *Service) UploadRaw(path string, data io.Reader, prepend string) (string, error)
- func (s *Service) UploadStaticImage(path string, data io.Reader, prepend string) (string, error)
- func (s *Service) UploadStaticRaw(path string, data io.Reader, prepend string) (string, error)
- func (s *Service) UploadVideo(path string, data io.Reader, prepend string) (string, error)
- func (s *Service) Url(publicId string, rtype ResourceType) string
- func (s *Service) UseDatabase(mongoDbURI string) error
- func (s *Service) Verbose(v bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureTrailingSlash ¶
EnsureTrailingSlash adds a missing trailing / at the end of a directory name.
Types ¶
type Resource ¶
type Resource struct { PublicId string `json:"public_id"` Version int `json:"version"` ResourceType string `json:"resource_type"` // image or raw Size int `json:"bytes"` // In bytes Url string `json:"url"` // Remote url SecureUrl string `json:"secure_url"` // Over https }
Resource holds information about an image or a raw file.
type ResourceDetails ¶
type ResourceDetails struct { PublicId string `json:"public_id"` Format string `json:"format"` Version int `json:"version"` ResourceType string `json:"resource_type"` // image or raw Size int `json:"bytes"` // In bytes Width int `json:"width"` // Width Height int `json:"height"` // Height Url string `json:"url"` // Remote url SecureUrl string `json:"secure_url"` // Over https Derived []*Derived `json:"derived"` // Derived }
type ResourceType ¶
type ResourceType int
const ( ImageType ResourceType = iota PdfType VideoType RawType )
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func Dial ¶
Dial will use the url to connect to the Cloudinary service. The uri parameter must be a valid URI with the cloudinary:// scheme, e.g.
cloudinary://api_key:api_secret@cloud_name
func (*Service) DefaultUploadURI ¶
DefaultUploadURI returns the default URI used to upload images to the Cloudinary service.
func (*Service) Delete ¶
func (s *Service) Delete(publicId, prepend string, rtype ResourceType) error
Delete deletes a resource uploaded to Cloudinary.
func (*Service) DropAll ¶
DropAll deletes all remote resources (both images and raw files) from Cloudinary. File names are written to io.Writer if available.
func (*Service) DropAllImages ¶
DropAllImages deletes all remote images from Cloudinary. File names are written to io.Writer if available.
func (*Service) DropAllRaws ¶
DropAllRaws deletes all remote raw files from Cloudinary. File names are written to io.Writer if available.
func (*Service) KeepFiles ¶
KeepFiles sets a regex pattern of remote public ids that won't be deleted by any Delete() command. This can be useful to forbid deletion of some remote resources. This regexp pattern applies to both image and raw data types.
func (*Service) Rename ¶
func (s *Service) Rename(publicID, toPublicID, prepend string, rtype ResourceType) error
func (*Service) ResourceDetails ¶
func (s *Service) ResourceDetails(publicId string) (*ResourceDetails, error)
GetResourceDetails gets the details of a single resource that is specified by publicId.
func (*Service) Resources ¶
func (s *Service) Resources(rtype ResourceType) ([]*Resource, error)
Resources returns a list of all uploaded resources. They can be images or raw files, depending on the resource type passed in rtype. Cloudinary can return a limited set of results. Pagination is supported, so the full set of results is returned.
func (*Service) Simulate ¶
Simulate show what would occur but actualy don't do anything. This is a dry-run.
func (*Service) Upload ¶
func (s *Service) Upload(path string, data io.Reader, prepend string, randomPublicId bool, rtype ResourceType) (string, error)
Upload a file or a set of files to the cloud. The path parameter is a file location or a directory. If the source path is a directory, all files are recursively uploaded to Cloudinary.
In order to upload content, path is always required (used to get the directory name or resource name if randomPublicId is false) but data can be nil. If data is non-nil the content of the file will be read from it. If data is nil, the function will try to open filename(s) specified by path.
If ramdomPublicId is true, the service generates a unique random public id. Otherwise, the resource's public id is computed using the absolute path of the file.
Set rtype to the target resource type, e.g. image or raw file.
For example, a raw file /tmp/css/default.css will be stored with a public name of css/default.css (raw file keeps its extension), but an image file /tmp/images/logo.png will be stored as images/logo.
The function returns the public identifier of the resource.
func (*Service) UploadImage ¶
func (*Service) UploadStaticImage ¶
func (*Service) UploadStaticRaw ¶
helpers
func (*Service) UploadVideo ¶
func (*Service) Url ¶
func (s *Service) Url(publicId string, rtype ResourceType) string
Url returns the complete access path in the cloud to the resource designed by publicId or the empty string if no match.
func (*Service) UseDatabase ¶
UseDatabase connects to a mongoDB database and stores upload JSON responses, along with a source file checksum to prevent uploading the same file twice. Stored information is used by Url() to build a public URL for accessing the uploaded resource.