cloudinary

package module
v0.0.0-...-16e8288 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 19 Imported by: 0

README

go-cloudinary
=============

A Go client library and CLI tool to upload static assets to the `Cloudinary`_ service.

.. _Cloudinary: http://www.cloudinary.com

Installation
------------

Install the CLI tool and the library with::

    go get github.com/gotsunami/go-cloudinary/cloudinary

Usage
-----

Usage::

    cloudinary [options] action settings.conf
    
where action is one of ``ls``, ``rm``, ``up`` or ``url``.

Create a config file ``settings.conf`` with a ``[cloudinary]`` section::

    [cloudinary]
    uri=cloudinary://api_key:api_secret@cloud_name

Type ``cloudinary`` in the terminal to get some help.

Uploading files
~~~~~~~~~~~~~~~

Use the ``up`` action to upload an image (or a directory of images) to Cloudinary with ``-i`` option::

    $ cloudinary -i /path/to/img.png up settings.conf
    $ cloudinary -i /path/to/images/ up settings.conf
    
In order to upload raw files, use the ``-r`` option. For example, a CSS file can be upload with::

    $ cloudinary -r /path/to/default.css up settings.conf

Raw files can be of any type (css, js, pdf etc.), even images if you don't
care about not using Cloudinary's image processing features.

List Remote Resources
~~~~~~~~~~~~~~~~~~~~~

Using the ``ls`` action will list all uploaded images and raw files::

    $ cloudinary ls settings.conf

Delete Remote Resources
~~~~~~~~~~~~~~~~~~~~~~~

Use the ``rm`` action to delete resources and give the ``-i`` or ``-r`` ``public_id`` for the resource::

    $ cloudinary -i img/home rm settings.conf
    $ cloudinary -r media/js/jquery-min.js rm settings.conf

Delete all remote resources(!) with::

    $ cloudinary -a rm settings.conf
    
In any case, you can always use the ``-s`` flag to simulate an action and see what result to expect.
i

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureTrailingSlash

func EnsureTrailingSlash(dirname string) string

EnsureTrailingSlash adds a missing trailing / at the end of a directory name.

Types

type Derived

type Derived struct {
	Transformation string `json:"transformation"` // Transformation
	Size           int    `json:"bytes"`          // In bytes
	Url            string `json:"url"`            // Remote url
}

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

func Dial(uri string) (*Service, error)

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) ApiKey

func (s *Service) ApiKey() string

ApiKey returns the API key used to access the Cloudinary service.

func (*Service) CloudName

func (s *Service) CloudName() string

CloudName returns the cloud name used to access the Cloudinary service.

func (*Service) DefaultUploadURI

func (s *Service) DefaultUploadURI() *url.URL

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

func (s *Service) DropAll(w io.Writer) error

DropAll deletes all remote resources (both images and raw files) from Cloudinary. File names are written to io.Writer if available.

func (*Service) DropAllImages

func (s *Service) DropAllImages(w io.Writer) error

DropAllImages deletes all remote images from Cloudinary. File names are written to io.Writer if available.

func (*Service) DropAllRaws

func (s *Service) DropAllRaws(w io.Writer) error

DropAllRaws deletes all remote raw files from Cloudinary. File names are written to io.Writer if available.

func (*Service) KeepFiles

func (s *Service) KeepFiles(pattern string) error

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

func (s *Service) Simulate(v bool)

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 (s *Service) UploadImage(path string, data io.Reader, prepend string) (string, error)

func (*Service) UploadPdf

func (s *Service) UploadPdf(path string, data io.Reader, prepend string) (string, error)

func (*Service) UploadRaw

func (s *Service) UploadRaw(path string, data io.Reader, prepend string) (string, error)

func (*Service) UploadStaticImage

func (s *Service) UploadStaticImage(path string, data io.Reader, prepend string) (string, error)

func (*Service) UploadStaticRaw

func (s *Service) UploadStaticRaw(path string, data io.Reader, prepend string) (string, error)

helpers

func (*Service) UploadVideo

func (s *Service) UploadVideo(path string, data io.Reader, prepend string) (string, error)

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

func (s *Service) UseDatabase(mongoDbURI string) error

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.

func (*Service) Verbose

func (s *Service) Verbose(v bool)

Verbose activate/desactivate debugging information on standard output.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL