cloudinary

package module
v2.16.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 6 Imported by: 244

README

Tests Go Report Card PkgGoDev License

Cloudinary Go SDK

Upload, transform, optimize, and manage images and videos with Cloudinary from Go — the cloudinary-go module.

Install

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

Quick start

Set your API environment variable (Console > Settings > API Keys):

export CLOUDINARY_URL=cloudinary://<api_key>:<api_secret>@<cloud_name>

Upload an image and get an optimized delivery URL:

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/cloudinary/cloudinary-go/v2"
	"github.com/cloudinary/cloudinary-go/v2/api/uploader"
)

func main() {
	if err := run(); err != nil {
		fmt.Fprintln(os.Stderr, "Quick start failed:", err)
		fmt.Fprintln(os.Stderr, "Check that CLOUDINARY_URL is set (Console > Settings > API Keys).")
		os.Exit(1)
	}
}

func run() error {
	cld, err := cloudinary.New()
	if err != nil {
		return err
	}
	ctx := context.Background()

	// Upload a remote image (a local file path works the same way).
	result, err := cld.Upload.Upload(ctx,
		"https://res.cloudinary.com/demo/image/upload/sample.jpg",
		uploader.UploadParams{PublicID: "quickstart-sample"})
	if err != nil {
		return err
	}
	if result.Error.Message != "" {
		// Cloudinary rejected the request; this arrives with err == nil.
		return fmt.Errorf("upload rejected: %s", result.Error.Message)
	}
	fmt.Println("Uploaded:", result.PublicID)

	// Build a 400x400 auto-cropped URL with automatic format and quality.
	image, err := cld.Image(result.PublicID)
	if err != nil {
		return err
	}
	image.Transformation = "c_fill,g_auto,h_400,w_400/f_auto,q_auto"
	url, err := image.String()
	if err != nil {
		return err
	}
	fmt.Println("Optimized URL:", url)
	return nil
}

Save as quickstart.go and run go run quickstart.go. Create a free account if you don't have one — or run npx @cloudinary/cloud to provision one without signing up.

Note the two checks in run: err reports transport, context, and decoding failures, while a Cloudinary rejection arrives with err == nil and a populated result.Error.Message. See Handle errors.

Common tasks

Runnable versions live in examples/ — each is a complete program you can run directly. It is a nested module, so run them from inside examples/.

When to use this SDK

Use this module in Go server-side code: uploads, signed operations, asset administration, search, moderation, and delivery URL generation.

For other jobs, better-fitting tools exist:

The full capability map — plus the Skills, MCP servers, and CLI worth setting up first — is in docs/platform-capabilities.md.

Status and compatibility

Stable, actively maintained. See CHANGELOG.md.

SDK version Go 1.13 - 1.19 Go 1.20 - 1.23 Go 1.24 - 1.27
2.8 and up ❌ ✔️ ✔️
2.7 ✔️ ✔️ ✔️
1.x ✔️ ✔️ ✔️

Documentation

Documentation links in this README point at the browsable HTML page, with an (md) companion link that returns the same page as raw Markdown. Inside docs/ and examples/ the links are Markdown-only, since those files are written to be read by coding agents. Either form works for any page: add .md for Markdown, drop it for HTML.

For AI coding agents

  • Contributing to this repo: read AGENTS.md.
  • Using the installed module: the docs bundled in the module match your resolved version and are the source of truth; start with platform-capabilities before assuming a feature exists.

Go has no fixed install path, so locate the bundled docs with:

go list -m -f '{{.Dir}}' github.com/cloudinary/cloudinary-go/v2
# then read <that path>/docs/README.md

Support

Contributing: see CONTRIBUTING.md.

Security

See SECURITY.md for private vulnerability reporting. Keep your api_secret in server-side code; for client uploads, use the server-signed pattern in Sign a browser upload.

License

Released under the MIT license — see LICENSE. Copyright (c) Cloudinary Ltd.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cloudinary

type Cloudinary struct {
	Config config.Configuration
	Admin  admin.API
	Upload uploader.API
	Logger *logger.Logger
}

Cloudinary main struct

func New

func New() (*Cloudinary, error)

New returns a new Cloudinary instance from environment variable.

func NewFromConfiguration

func NewFromConfiguration(configuration config.Configuration) (*Cloudinary, error)

NewFromConfiguration returns a new Cloudinary instance from the provided configuration.

func NewFromOAuthToken

func NewFromOAuthToken(cloud string, oAuthToken string) (*Cloudinary, error)

NewFromOAuthToken returns a new Cloudinary instance from the provided cloud name and OAuth token.

func NewFromParams

func NewFromParams(cloud string, key string, secret string) (*Cloudinary, error)

NewFromParams returns a new Cloudinary instance from the provided parameters.

func NewFromURL

func NewFromURL(cloudinaryURL string) (*Cloudinary, error)

NewFromURL returns a new Cloudinary instance from a cloudinary url.

func (Cloudinary) File

func (c Cloudinary) File(publicID string) (*asset.Asset, error)

File creates a new asset.File instance.

func (Cloudinary) Image

func (c Cloudinary) Image(publicID string) (*asset.Asset, error)

Image creates a new asset.Image instance.

func (Cloudinary) Media

func (c Cloudinary) Media(publicID string) (*asset.Asset, error)

Media creates a new asset.Media instance.

func (Cloudinary) SearchURL added in v2.3.0

func (c Cloudinary) SearchURL(query search.Query) (*asset.SearchURLAsset, error)

SearchURL creates a new asset.SearchURL instance.

func (Cloudinary) Video

func (c Cloudinary) Video(publicID string) (*asset.Asset, error)

Video creates a new asset.Video instance.

Directories

Path Synopsis
api
Package api contains packages used for accessing Cloudinary API functionality.
Package api contains packages used for accessing Cloudinary API functionality.
admin
Package admin is used for accessing Cloudinary Admin API functionality.
Package admin is used for accessing Cloudinary Admin API functionality.
admin/metadata
Package metadata defines the structured metadata.
Package metadata defines the structured metadata.
uploader
Package uploader is used for accessing Cloudinary Upload API functionality.
Package uploader is used for accessing Cloudinary Upload API functionality.
Package config defines the Cloudinary configuration.
Package config defines the Cloudinary configuration.
gen
internal
Package logger defines the Cloudinary Logger
Package logger defines the Cloudinary Logger
Package transformation defines Cloudinary Transformation.
Package transformation defines Cloudinary Transformation.

Jump to

Keyboard shortcuts

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