uploader

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 16 Imported by: 51

Documentation

Overview

Package uploader is used for accessing Cloudinary Upload API functionality.

https://cloudinary.com/documentation/image_upload_api_reference

Index

Constants

View Source
const (
	GenerateArchive api.EndPoint = "generate_archive"
	DownloadBackup  api.EndPoint = "download_backup"
)
View Source
const (
	Sprite  api.EndPoint = "sprite"
	Multi   api.EndPoint = "multi"
	Explode api.EndPoint = "explode"
	Text    api.EndPoint = "text"
)
View Source
const (
	Upload   api.EndPoint = "upload"
	Destroy  api.EndPoint = "destroy"
	Rename   api.EndPoint = "rename"
	Explicit api.EndPoint = "explicit"
	Metadata api.EndPoint = "metadata"
)
View Source
const (
	Context api.EndPoint = "context"
)
View Source
const (
	Tags api.EndPoint = "tags"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddContextParams

type AddContextParams struct {
	Context      api.CldApiMap   `json:"context,omitempty"`
	PublicIDs    api.CldApiArray `json:"public_ids"`
	Type         string          `json:"type,omitempty"`
	ResourceType string          `json:"-"`
}

AddContextParams struct

type AddContextResult

type AddContextResult struct {
	ContextResult
}

type AddTagParams

type AddTagParams struct {
	Tag          string          `json:"tag,omitempty"` // The name of the tag to add.
	PublicIDs    api.CldApiArray `json:"public_ids"`    // The public IDs of the assets to add the tag to.
	Type         string          `json:"type,omitempty"`
	ResourceType string          `json:"-"`
}

AddTagParams struct

type AddTagResult

type AddTagResult struct {
	TagResult
}

type Api

type Api struct {
	Config config.Configuration
	// contains filtered or unexported fields
}

Upload Api main struct

func Create

func Create() (*Api, error)

Create creates a new Admin Api instance from the environment variable.

func (*Api) AddContext

func (u *Api) AddContext(ctx context.Context, params AddContextParams) (*AddContextResult, error)

AddContext adds context metadata as key-value pairs to the the specified assets.

https://cloudinary.com/documentation/image_upload_api_reference#context_method

func (*Api) AddTag

func (u *Api) AddTag(ctx context.Context, params AddTagParams) (*AddTagResult, error)

AddTag adds a tag to the assets specified.

https://cloudinary.com/documentation/image_upload_api_reference#tags_method

func (*Api) CreateArchive

func (u *Api) CreateArchive(ctx context.Context, params CreateArchiveParams) (*CreateArchiveResult, error)

CreateArchive creates a new archive in the server and returns information in JSON format.

func (*Api) CreateZip

func (u *Api) CreateZip(ctx context.Context, params CreateArchiveParams) (*CreateArchiveResult, error)

CreateZip creates a new zip archive in the server and returns information in JSON format.

func (*Api) Destroy

func (u *Api) Destroy(ctx context.Context, params DestroyParams) (*DestroyResult, error)

Destroy immediately and permanently deletes a single asset from your Cloudinary account.

Backed up assets are not deleted, and any assets and transformed assets already downloaded by visitors to your website might still be accessible through cached copies on the CDN. You can invalidate any cached copies on the CDN with the `Invalidate` parameter.

https://cloudinary.com/documentation/image_upload_api_reference#destroy_method

func (*Api) DownloadArchiveUrl

func (u *Api) DownloadArchiveUrl(params CreateArchiveParams) (string, error)

DownloadArchiveUrl creates a URL that when invoked generates an archive and returns it.

func (*Api) DownloadBackedUpAsset

func (u *Api) DownloadBackedUpAsset(params DownloadABackedUpAssetParams) (string, error)

DownloadBackedUpAsset creates a URL that allows downloading the backed-up asset based on the asset ID and the version ID.

func (*Api) DownloadFolder

func (u *Api) DownloadFolder(folderPath string, params CreateArchiveParams) (string, error)

DownloadFolder creates a URL that when invoked generates an archive of a folder.

func (*Api) DownloadZipUrl

func (u *Api) DownloadZipUrl(params CreateArchiveParams) (string, error)

DownloadZipUrl creates a URL that when invokes generates a zip archive and returns it.

func (*Api) Explicit

func (u *Api) Explicit(ctx context.Context, params ExplicitParams) (*ExplicitResult, error)

Explicit applies actions to already uploaded assets.

https://cloudinary.com/documentation/image_upload_api_reference#explicit_method

func (*Api) Explode

func (u *Api) Explode(ctx context.Context, params ExplodeParams) (*ExplodeResult, error)

Explode creates derived images for all of the individual pages in a multi-page file (PDF or animated GIF).

Each derived image is stored with the same public ID as the original file, and can be accessed using the page parameter, in order to deliver a specific image.

https://cloudinary.com/documentation/image_upload_api_reference#explode_method

func (*Api) GenerateSprite

func (u *Api) GenerateSprite(ctx context.Context, params GenerateSpriteParams) (*GenerateSpriteResult, error)

GenerateSprite creates a sprite from all images that have been assigned a specified tag.

The process produces two files: * A single image file containing all the images with the specified tag (PNG by default). * A CSS file that includes the style class names and the location of the individual images in the sprite.

https://cloudinary.com/documentation/image_upload_api_reference#sprite_method

func (*Api) Multi

func (u *Api) Multi(ctx context.Context, params MultiParams) (*MultiResult, error)

Multi Creates a single animated image, video or PDF from all image assets that have been assigned a specified tag.

https://cloudinary.com/documentation/image_upload_api_reference#multi_method

func (*Api) RemoveAllContext

func (u *Api) RemoveAllContext(ctx context.Context, params RemoveAllContextParams) (*RemoveAllContextResult, error)

RemoveAllContext removes all context metadata from the specified assets.

https://cloudinary.com/documentation/image_upload_api_reference#context_method

func (*Api) RemoveAllTags

func (u *Api) RemoveAllTags(ctx context.Context, params RemoveAllTagsParams) (*RemoveAllTagsResult, error)

RemoveAllTags removes all tags from the assets specified.

https://cloudinary.com/documentation/image_upload_api_reference#tags_method

func (*Api) RemoveTag

func (u *Api) RemoveTag(ctx context.Context, params RemoveTagParams) (*RemoveTagResult, error)

RemoveTag removes a tag from the assets specified.

https://cloudinary.com/documentation/image_upload_api_reference#tags_method

func (*Api) Rename

func (u *Api) Rename(ctx context.Context, params RenameParams) (*RenameResult, error)

Rename renames the specified asset in your Cloudinary account.

The existing URLs of renamed assets and their associated derived resources are no longer valid, although any assets and transformed assets already downloaded by visitors to your website might still be accessible through cached copies on the CDN. You can invalidate any cached copies on the CDN with the `invalidate` parameter.

https://cloudinary.com/documentation/image_upload_api_reference#rename_method

func (*Api) ReplaceTag

func (u *Api) ReplaceTag(ctx context.Context, params ReplaceTagParams) (*ReplaceTagResult, error)

Replaces all existing tags on the assets specified with the tag specified.

https://cloudinary.com/documentation/image_upload_api_reference#tags_method

func (*Api) UnsignedUpload

func (u *Api) UnsignedUpload(ctx context.Context, file string, uploadPreset string, uploadParams UploadParams) (*UploadResult, error)

UnsignedUpload uploads an asset to a Cloudinary account.

The upload is not signed so an upload preset is required.

https://cloudinary.com/documentation/image_upload_api_reference#unsigned_upload_syntax

func (*Api) UpdateMetadata

func (u *Api) UpdateMetadata(ctx context.Context, params RenameParams) (*UpdateMetadataResult, error)

UpdateMetadata populates metadata fields with the given values. Existing values will be overwritten.

Any metadata-value pairs given are merged with any existing metadata-value pairs (an empty value for an existing metadata field clears the value).

https://cloudinary.com/documentation/image_upload_api_reference#metadata_method

func (*Api) Upload

func (u *Api) Upload(ctx context.Context, file interface{}, uploadParams UploadParams) (*UploadResult, error)

Upload uploads an asset to a Cloudinary account.

The asset can be:

  • a local file path
  • the actual data (io.Reader)
  • the Data URI (Base64 encoded), max ~60 MB (62,910,000 chars)
  • the remote FTP, HTTP or HTTPS URL address of an existing file
  • a private storage bucket (S3 or Google Storage) URL of a whitelisted bucket

https://cloudinary.com/documentation/image_upload_api_reference#upload_method

type ArchiveFormat

type ArchiveFormat string
const (
	Zip ArchiveFormat = "zip"
	Tgz ArchiveFormat = "tgz"
)

type ArchiveMode

type ArchiveMode string
const (
	CreateArchive   ArchiveMode = "create"
	DownloadArchive ArchiveMode = "download"
)

type ContextCommand

type ContextCommand string
const (
	AddContext       ContextCommand = "add"
	RemoveAllContext ContextCommand = "remove_all"
)

type ContextResult

type ContextResult struct {
	PublicIds []string      `json:"public_ids"`
	Error     api.ErrorResp `json:"error,omitempty"`
	Response  http.Response
}

type CreateArchiveParams

type CreateArchiveParams struct {
	AllowMissing            bool             `json:"allow_mising,omitempty"`
	Async                   bool             `json:"async,omitempty"`
	ExpiresAt               *time.Time       `json:"expires_at,omitempty"`
	FlattenFolders          bool             `json:"flatten_folders,omitempty"`
	FlattenTransformations  bool             `json:"flatten_transformations,omitempty"`
	FullyQualifiedPublicIds api.CldApiArray  `json:"fully_qualified_public_ids,omitempty"`
	KeepDerived             bool             `json:"keep_derived,omitempty"`
	Mode                    ArchiveMode      `json:"mode,omitempty"`
	NotificationUrl         string           `json:"notification_url,omitempty"`
	Phash                   string           `json:"phash,omitempty"`
	Prefixes                api.CldApiArray  `json:"prefixes,omitempty"`
	PublicIds               api.CldApiArray  `json:"public_ids,omitempty"`
	ResourceType            api.AssetType    `json:"-"`
	SkipTransformationName  bool             `json:"skip_transformation_name,omitempty"`
	TargetFormat            ArchiveFormat    `json:"target_format,omitempty"`
	TargetPublicId          string           `json:"target_public_id,omitempty"`
	TargetTags              api.CldApiArray  `json:"target_tags,omitempty"`
	Tags                    api.CldApiArray  `json:"tags,omitempty"`
	Transformations         string           `json:"transformations,omitempty"`
	Type                    api.DeliveryType `json:"type,omitempty"`
	UseOriginalFilename     bool             `json:"use_original_filename,omitempty"`
}

CreateArchiveParams struct

type CreateArchiveResult

type CreateArchiveResult struct {
	AssetID       string        `json:"asset_id"`
	PublicID      string        `json:"public_id"`
	Version       int           `json:"version"`
	VersionID     string        `json:"version_id"`
	Signature     string        `json:"signature"`
	ResourceType  string        `json:"resource_type"`
	CreatedAt     time.Time     `json:"created_at"`
	Tags          []string      `json:"tags"`
	Bytes         int           `json:"bytes"`
	Type          string        `json:"type"`
	Etag          string        `json:"etag"`
	Placeholder   bool          `json:"placeholder"`
	URL           string        `json:"url"`
	SecureURL     string        `json:"secure_url"`
	AccessMode    string        `json:"access_mode"`
	ResourceCount int           `json:"resource_count"`
	FileCount     int           `json:"file_count"`
	Error         api.ErrorResp `json:"error,omitempty"`
	Response      http.Response
}

type DestroyParams

type DestroyParams struct {
	PublicID     string `json:"public_id,omitempty"`
	Type         string `json:"type,omitempty"`
	ResourceType string `json:"-"`
	Invalidate   bool   `json:"invalidate,omitempty"`
}

DestroyParams struct

type DestroyResult

type DestroyResult struct {
	Result   string        `json:"result"`
	Error    api.ErrorResp `json:"error,omitempty"`
	Response http.Response
}

type DownloadABackedUpAssetParams

type DownloadABackedUpAssetParams struct {
	AssetID   string `json:"asset_id"`
	VersionID string `json:"version_id,omitempty"`
}

type ExplicitParams

type ExplicitParams = UploadParams

type ExplicitResult

type ExplicitResult struct {
	UploadResult
}

type ExplodeParams

type ExplodeParams struct {
	PublicID        string `json:"public_id"`
	Format          string `json:"format,omitempty"`
	Type            string `json:"type,omitempty"`
	NotificationUrl string `json:"notification_url,omitempty"`
	Transformation  string `json:"transformation,omitempty"`
	ResourceType    string `json:"-"`
}

ExplodeParams struct

type ExplodeResult

type ExplodeResult struct {
	Status   string        `json:"status"`
	BatchID  string        `json:"batch_id"`
	Error    api.ErrorResp `json:"error,omitempty"`
	Response http.Response
}

type GenerateSpriteParams

type GenerateSpriteParams struct {
	Tag             string `json:"tag,omitempty"`
	NotificationUrl string `json:"notification_url,omitempty"`
	Async           bool   `json:"async,omitempty"`
	Transformation  string `json:"transformation,omitempty"`
	ResourceType    string `json:"-"`
}

GenerateSpriteParams struct

type GenerateSpriteResult

type GenerateSpriteResult struct {
	CssUrl         string               `json:"css_url"`
	ImageUrl       string               `json:"image_url"`
	SecureCssUrl   string               `json:"secure_css_url"`
	SecureImageURL string               `json:"secure_image_url"`
	JsonUrl        string               `json:"json_url"`
	SecureJsonUrl  string               `json:"secure_json_url"`
	Version        int                  `json:"version"`
	PublicID       string               `json:"public_id"`
	ImageInfos     map[string]ImageInfo `json:"image_infos"`
	Error          api.ErrorResp        `json:"error,omitempty"`
	Response       http.Response
}

type ImageInfo

type ImageInfo struct {
	Width  int `json:"width"`
	Height int `json:"height"`
	X      int `json:"x"`
	Y      int `json:"y"`
}

type MultiParams

type MultiParams struct {
	Tag             string `json:"tag,omitempty"`
	Format          string `json:"format,omitempty"`
	NotificationUrl string `json:"notification_url,omitempty"`
	Async           bool   `json:"async,omitempty"`
	Transformation  string `json:"transformation,omitempty"`
	ResourceType    string `json:"-"`
}

MultiParams struct

type MultiResult

type MultiResult struct {
	Url       string        `json:"url"`
	SecureUrl string        `json:"secure_url"`
	AssetID   string        `json:"asset_id"`
	PublicID  string        `json:"public_id"`
	Version   int           `json:"version"`
	Error     api.ErrorResp `json:"error,omitempty"`
	Response  http.Response
}

type RemoveAllContextParams

type RemoveAllContextParams struct {
	PublicIDs    api.CldApiArray `json:"public_ids"`
	Type         string          `json:"type,omitempty"`
	ResourceType string          `json:"-"`
}

RemoveAllContextParams struct

type RemoveAllContextResult

type RemoveAllContextResult struct {
	ContextResult
}

type RemoveAllTagsParams

type RemoveAllTagsParams struct {
	PublicIDs    api.CldApiArray `json:"public_ids"` // The public IDs of the assets to remove all tags from.
	Type         string          `json:"type,omitempty"`
	ResourceType string          `json:"-"`
}

RemoveTagParams struct

type RemoveAllTagsResult

type RemoveAllTagsResult struct {
	TagResult
}

type RemoveTagParams

type RemoveTagParams struct {
	Tag          string          `json:"tag,omitempty"` // The name of the tag to remove.
	PublicIDs    api.CldApiArray `json:"public_ids"`    // The public IDs of the assets to remove the tags from.
	Type         string          `json:"type,omitempty"`
	ResourceType string          `json:"-"`
}

RemoveTagParams struct

type RemoveTagResult

type RemoveTagResult struct {
	TagResult
}

type RenameParams

type RenameParams struct {
	FromPublicID string `json:"from_public_id,omitempty"`
	ToPublicID   string `json:"to_public_id,omitempty"`
	Type         string `json:"type,omitempty"`
	ToType       string `json:"to_type,omitempty"`
	ResourceType string `json:"-"`
	Overwrite    bool   `json:"overwrite,omitempty"`
	Invalidate   bool   `json:"invalidate,omitempty"`
}

RenameParams struct

type RenameResult

type RenameResult struct {
	api.BriefAssetResult
	Error interface{} `json:"error,omitempty"`
}

type ReplaceTagParams

type ReplaceTagParams struct {
	Tag          string          `json:"tag"`        // The new tag with which to replace the existing tags.
	PublicIDs    api.CldApiArray `json:"public_ids"` // The public IDs of the assets to replace the tags of.
	Type         string          `json:"type,omitempty"`
	ResourceType string          `json:"-"`
}

ReplaceTagParams struct

type ReplaceTagResult

type ReplaceTagResult struct {
	TagResult
}

type TagCommand

type TagCommand string
const (
	AddTag        TagCommand = "add"
	RemoveTag     TagCommand = "remove"
	ReplaceTag    TagCommand = "replace"
	RemoveAllTags TagCommand = "remove_all"
)

type TagResult

type TagResult struct {
	PublicIds []string      `json:"public_ids"` // The public IDs of the assets that were affected.
	Error     api.ErrorResp `json:"error,omitempty"`
	Response  http.Response
}

type UpdateMetadataParams

type UpdateMetadataParams struct {
	PublicIDs api.CldApiArray `json:"public_ids"`
	Metadata  api.Metadata    `json:"metadata"`
	Type      string          `json:"type,omitempty"`
}

UpdateMetadataParams struct

type UpdateMetadataResult

type UpdateMetadataResult struct {
	PublicIds []string    `json:"public_ids"`
	Error     interface{} `json:"error,omitempty"`
}

type UploadParams

type UploadParams struct {
	PublicID                string           `json:"public_id,omitempty"`
	PublicIds               api.CldApiArray  `json:"public_ids,omitempty"`
	UseFilename             bool             `json:"use_filename,omitempty"`
	UniqueFilename          bool             `json:"unique_filename,omitempty"`
	Folder                  string           `json:"folder,omitempty"`
	Overwrite               bool             `json:"overwrite,omitempty"`
	ResourceType            string           `json:"resource_type,omitempty"`
	Type                    api.DeliveryType `json:"type,omitempty"`
	Tags                    api.CldApiArray  `json:"tags,omitempty"`
	Context                 api.CldApiMap    `json:"context,omitempty"`
	Metadata                api.Metadata     `json:"metadata,omitempty"`
	Transformation          string           `json:"transformation,omitempty"`
	Format                  string           `json:"format,omitempty"`
	AllowedFormats          api.CldApiArray  `json:"allowed_formats,omitempty"`
	Eager                   string           `json:"eager,omitempty"`
	Eval                    string           `json:"eval,omitempty"`
	Async                   bool             `json:"async,omitempty"`
	EagerAsync              bool             `json:"eager_async,omitempty"`
	Unsigned                bool             `json:"unsigned,omitempty"`
	Proxy                   string           `json:"proxy,omitempty"`
	Headers                 string           `json:"headers,omitempty"`
	Callback                string           `json:"callback,omitempty"`
	NotificationURL         string           `json:"notification_url,omitempty"`
	EagerNotificationURL    string           `json:"eager_notification_url,omitempty"`
	Faces                   bool             `json:"faces,omitempty"`
	ImageMetadata           bool             `json:"image_metadata,omitempty"`
	Exif                    bool             `json:"exif,omitempty"`
	Colors                  bool             `json:"colors,omitempty"`
	Phash                   bool             `json:"phash,omitempty"`
	FaceCoordinates         api.Coordinates  `json:"face_coordinates,omitempty"`
	CustomCoordinates       api.Coordinates  `json:"custom_coordinates,omitempty"`
	Backup                  bool             `json:"backup,omitempty"`
	ReturnDeleteToken       bool             `json:"return_delete_token,omitempty"`
	Invalidate              bool             `json:"invalidate,omitempty"`
	DiscardOriginalFilename bool             `json:"discard_original_filename,omitempty"`
	Moderation              string           `json:"moderation,omitempty"`
	UploadPreset            string           `json:"upload_preset,omitempty"`
	RawConvert              string           `json:"raw_convert,omitempty"`
	Categorization          string           `json:"categorization,omitempty"`
	AutoTagging             float64          `json:"auto_tagging,omitempty"`
	BackgroundRemoval       string           `json:"background_removal,omitempty"`
	Detection               string           `json:"detection,omitempty"`
	OCR                     string           `json:"ocr,omitempty"`
	Timestamp               time.Time        `json:"timestamp,omitempty"`
	QualityAnalysis         bool             `json:"quality_analysis,omitempty"`
	AccessibilityAnalysis   bool             `json:"accessibility_analysis,omitempty"`
	CinemagraphAnalysis     bool             `json:"cinemagraph_analysis,omitempty"`
}

UploadParams struct

http://cloudinary.com/documentation/image_upload_api_reference#api_example_1

type UploadResult

type UploadResult struct {
	AssetID          string          `json:"asset_id"`
	PublicID         string          `json:"public_id"`
	Version          int             `json:"version"`
	VersionID        string          `json:"version_id"`
	Signature        string          `json:"signature"`
	Width            int             `json:"width,omitempty"`
	Height           int             `json:"height,omitempty"`
	Format           string          `json:"format"`
	ResourceType     string          `json:"resource_type"`
	CreatedAt        time.Time       `json:"created_at"`
	Tags             api.CldApiArray `json:"tags,omitempty"`
	Pages            int             `json:"pages,omitempty"`
	Bytes            int             `json:"bytes"`
	Type             string          `json:"type"`
	Etag             string          `json:"etag"`
	Placeholder      bool            `json:"placeholder,omitempty"`
	URL              string          `json:"url"`
	SecureURL        string          `json:"secure_url"`
	AccessMode       string          `json:"access_mode"`
	Context          api.CldApiMap   `json:"context,omitempty"`
	Metadata         api.Metadata    `json:"metadata,omitempty"`
	Overwritten      bool            `json:"overwritten"`
	OriginalFilename string          `json:"original_filename"`
	Error            api.ErrorResp   `json:"error,omitempty"`
}

UploadResult image success response struct

Jump to

Keyboard shortcuts

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