imagekit

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: MIT Imports: 15 Imported by: 7

README

imagekit-go

A Go client library for accessing the ImageKit.io API.

Installation

Use the following command to download this module:

go get github.com/codedius/imagekit-go

Usage

import "github.com/codedius/imagekit-go"

Construct a new API client, then use to access the ImageKit.io API. For example:

opts := imagekit.Options{
    PublicKey:  "Your API Private Key",
    PrivateKey: "Your API Public Key",
}

ik, err := imagekit.NewClient(&opts)
if err != nil {
    // error handling
}

Upload image to your ImageKit.io Media Library:

ur := imagekit.UploadRequest{
    File:              file, // []byte OR *url.URL OR url.URL OR base64 string
    FileName:          "file name",
    UseUniqueFileName: false,
    Tags:              []string{},
    Folder:            "/",
    IsPrivateFile:     false,
    CustomCoordinates: "",
    ResponseFields:    nil,
}

ctx := context.Background()

upr, err := ik.Upload.ServerUpload(ctx, &ur)
if err != nil {
    // error handling
}

Other methods are pretty straightforward and doesn't need extra explanations. For more info please read library's documentation from go.dev and ImageKit.io API documentation.

Documentation

Overview

Package imagekit provides Go client to work with Imagekit.io image processing service API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddTagsRequest added in v1.1.0

type AddTagsRequest struct {
	// FileIDs is the list of unique ID of the uploaded files.
	FileIDs []string `json:"fileIds"`
	// Tags is an array of tags to add on these files.
	Tags []string `json:"tags"`
}

type BulkJobStatusResponse added in v1.1.0

type BulkJobStatusResponse struct {
	// JobID you get in the response of bulk job API e.g. copy folder or move folder API.
	JobID string `json:"jobId"`
	// Type of operation, it could be either COPY_FOLDER or MOVE_FOLDER.
	Type string `json:"type"`
	// Status of the job.
	//
	// It can be either:
	// Pending - The job has been successfully submitted and is in progress.
	// Completed - The job has been completed.
	Status string `json:"status"`
}

type Client

type Client struct {

	// Upload API.
	Upload *UploadService
	// Media API.
	Media *MediaService
	// Metadata API.
	Metadata *MetadataService
	// contains filtered or unexported fields
}

Client manages communication with the API.

func NewClient

func NewClient(opts *Options) (*Client, error)

NewClient returns a new API client.

type CopyFileRequest added in v1.1.0

type CopyFileRequest struct {
	// SourceFilePath is the full path of the file you want to copy.
	//
	// For example - /path/to/file.jpg
	SourceFilePath string `json:"sourceFilePath"`
	// DestinationPath is the full path to the folder you want to copy the above file into.
	//
	// For example - /folder/to/copy/into/
	DestinationPath string `json:"destinationPath"`
}

type CopyFolderRequest added in v1.1.0

type CopyFolderRequest struct {
	// SourceFolderPath is the full path to the source folder you want to copy.
	//
	// For example - /path/of/source/folder
	SourceFolderPath string `json:"sourceFolderPath"`
	// DestinationPath is the full path to the destination folder where you want to copy the source folder into.
	//
	// For example - /path/of/destination/folder/
	DestinationPath string `json:"destinationPath"`
}

type CopyFolderResponse added in v1.1.0

type CopyFolderResponse struct {
	JobID string `json:"jobId"`
}

type CreateFolderRequest added in v1.1.0

type CreateFolderRequest struct {
	// FolderName of the folder to create.
	//
	// All characters except alphabets and numbers will be replaced by an underscore i.e. _
	FolderName string `json:"folderName"`
	// ParentFolderPath where the new folder should be created.
	//
	// For root use / else containing/folder/
	// Note: If any folder(s) is not present in the parentFolderPath parameter, it will be automatically created. For example,
	// if you pass /product/images/summer, then product, images, and summer folders will be created if they don't already exist.
	ParentFolderPath string `json:"parentFolderPath"`
}

type DeleteFilesRequest

type DeleteFilesRequest struct {
	// FileIDs is the list of unique ID of the uploaded files.
	FileIDs []string `json:"fileIds"`
}

type DeleteFilesResponse

type DeleteFilesResponse struct {
	// SuccessfullyDeletedFileIDs is the array of fileIds which are successfully deleted.
	SuccessfullyDeletedFileIDs []string `json:"successfullyDeletedFileIds"`
}

type DeleteFolderRequest added in v1.1.0

type DeleteFolderRequest struct {
	// FolderPath is a full path to the folder you want to delete.
	//
	// For example folder/to/delete/
	FolderPath string `json:"folderPath"`
}

type ErrorResponse

type ErrorResponse struct {
	Response       *http.Response
	Message        string   `json:"message"`
	Help           string   `json:"help"`
	MissingFileIDs []string `json:"missingFileIds,omitempty"`
}

ErrorResponse reports error caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

Errors provides string error of error repsponse r.

type GetFileDetailsResponse

type GetFileDetailsResponse struct {
	// FileID is the unique ID of the uploaded file.
	FileID string `json:"fileId"`
	// Type of item. It can be either file or imageFolder.
	Type string `json:"type"`
	// Name of the file or imageFolder.
	Name string `json:"name"`
	// FilePath of the file. In the case of an image, you can use this path to construct different transform.
	FilePath string `json:"filePath"`
	// Tags is array of tags associated with the image.
	Tags []string `json:"tags"`
	// IsPrivateFile is the file marked as private. It can be either "true" or "false".
	IsPrivateFile bool `json:"isPrivateFile"`
	// CustomCoordinates is the value of custom coordinates associated with the image in format "x,y,width,height".
	CustomCoordinates string `json:"customCoordinates"`
	// URL of the file.
	URL string `json:"url"`
	// Thumbnail is a small thumbnail URL in case of an image.
	Thumbnail string `json:"thumbnail"`
	// FileType of the file, it could be either image or non-image.
	FileType string `json:"fileType"`
	// MIME Type of the file.
	MIME string `json:"mime"`
	// Height of the uploaded image file.
	//
	// Only applicable when file type is image.
	Height int `json:"height"`
	// Width of the uploaded image file.
	//
	// Only applicable when file type is image.
	Width int `json:"width"`
	// Size of the uploaded file in bytes.
	Size int `json:"size"`
	// HasAlpha is whether the image has an alpha component or not.
	HasAlpha bool `json:"hasAlpha"`
	// The date and time when the file was first uploaded.
	//
	// The format is YYYY-MM-DDTHH:mm:ss.sssZ
	CreatedAt time.Time `json:"created_at"`
}

type ListAndSearchFileRequest

type ListAndSearchFileRequest struct {
	// Path if you want to limit the search within a specific imageFolder.
	//
	// For example, /sales-banner/ will only search in imageFolder sales-banner.
	Path string
	// FileType to include in result set.
	//
	// Accepts three values:
	// all - include all types of files in result set
	// image - only search in image type files
	// non-image - only search in files which are not image, e.g., JS or CSS or video files.
	// Default value - all.
	FileType string
	// Files matching any of the Tags are included in result response.
	//
	// If no tag is matched, the file is not included in result set.
	Tags []string
	// IncludeFolder in search results or not. By default only files are searched.
	//
	// Accepts true and false. If this is set to true then tags and FileType parameters are ignored.
	IncludeFolder bool
	// Name of the file or imageFolder.
	Name string
	// Limit the maximum number of results to return in response.
	//
	// Minimum value - 1
	// Maximum value - 1000
	// Default value - 1000
	Limit int
	// Skip the number of results before returning results.
	//
	// Minimum value - 0
	// Default value - 0
	Skip int
}

type ListAndSearchFileResponse

type ListAndSearchFileResponse struct {
	// FileID is the unique ID of the uploaded file.
	FileID string `json:"fileId"`
	// Type of item. It can be either file or imageFolder.
	Type string `json:"type"`
	// Name of the file or imageFolder.
	Name string `json:"name"`
	// FilePath of the file. In the case of an image, you can use this path to construct different transform.
	FilePath string `json:"filePath"`
	// Tags is array of tags associated with the image.
	Tags []string `json:"tags"`
	// IsPrivateFile is the file marked as private. It can be either "true" or "false".
	IsPrivateFile bool `json:"isPrivateFile"`
	// CustomCoordinates is the value of custom coordinates associated with the image in format "x,y,width,height".
	CustomCoordinates string `json:"customCoordinates"`
	// URL of the file.
	URL string `json:"url"`
	// Thumbnail is a small thumbnail URL in case of an image.
	Thumbnail string `json:"thumbnail"`
	// FileType of the file, it could be either image or non-image.
	FileType string `json:"fileType"`
	// MIME Type of the file.
	MIME string `json:"mime"`
	// Height of the uploaded image file.
	//
	// Only applicable when file type is image.
	Height int `json:"height"`
	// Width of the uploaded image file.
	//
	// Only applicable when file type is image.
	Width int `json:"width"`
	// Size of the uploaded file in bytes.
	Size int `json:"size"`
	// HasAlpha is whether the image has an alpha component or not.
	HasAlpha bool `json:"hasAlpha"`
	// The date and time when the file was first uploaded.
	//
	// The format is YYYY-MM-DDTHH:mm:ss.sssZ
	CreatedAt time.Time `json:"created_at"`
}

type MediaService

type MediaService service

MediaService handles communication with the media related methods of the Imagekit.io API.

func (*MediaService) AddTags added in v1.1.0

func (s *MediaService) AddTags(ctx context.Context, r *AddTagsRequest) error

AddTags to multiple files in a single request.

func (*MediaService) BulkJobStatus added in v1.1.0

func (s *MediaService) BulkJobStatus(ctx context.Context, jid string) (*BulkJobStatusResponse, error)

BulkJobStatus will copy one folder into another.

func (*MediaService) CopyFile added in v1.1.0

func (s *MediaService) CopyFile(ctx context.Context, r *CopyFileRequest) error

CopyFile will copy a file from one folder to another.

func (*MediaService) CopyFolder added in v1.1.0

CopyFolder will copy one folder into another.

func (*MediaService) CreateFolder added in v1.1.0

func (s *MediaService) CreateFolder(ctx context.Context, r *CreateFolderRequest) error

CreateFolder will create a new folder.

You can specify the folder name and location of the parent folder where this new folder should be created.

func (*MediaService) DeleteFile

func (s *MediaService) DeleteFile(ctx context.Context, fid string) error

DeleteFile deletes file with id and all its transform.

func (*MediaService) DeleteFiles

DeleteFiles deletes multiple files uploaded in media library using bulk file delete API.

When you delete a file, all its transform are also deleted. However, if a file or specific transformation has been requested in the past, then the response is cached in CDN. You can purge the cache from the CDN using purge API.

func (*MediaService) DeleteFolder added in v1.1.0

func (s *MediaService) DeleteFolder(ctx context.Context, r *DeleteFolderRequest) error

DeleteFolder will delete the specified folder and all nested files & folders.

This action is cannot be undone.

func (*MediaService) GetFileDetails

func (s *MediaService) GetFileDetails(ctx context.Context, fid string) (*GetFileDetailsResponse, error)

GetFileDetails such as tags, customCoordinates, and isPrivate properties using get file detail API.

func (*MediaService) ListAndSearchFile

ListAndSearchFile lists all the uploaded files in your Imagekit.io media library.

func (*MediaService) MoveFile added in v1.1.0

func (s *MediaService) MoveFile(ctx context.Context, r *MoveFileRequest) error

MoveFile will move a file from one folder to another.

func (*MediaService) MoveFolder added in v1.1.0

MoveFolder will move one folder into another.

func (*MediaService) PurgeCache

PurgeCache will purge CDN and Imagekit.io internal cache.

func (*MediaService) PurgeCacheStatus

func (s *MediaService) PurgeCacheStatus(ctx context.Context, rid string) (*PurgeCacheStatusResponse, error)

PurgeCacheStatus gets the status of submitted purge request.

func (*MediaService) RemoveTags added in v1.1.0

func (s *MediaService) RemoveTags(ctx context.Context, r *RemoveTagsRequest) error

RemoveTags from multiple files in a single request.

func (*MediaService) UpdateFileDetails

UpdateFileDetails such as tags, customCoordinates, and isPrivate properties using get file detail API.

type MetadataEXIF

type MetadataEXIF struct {
	ApertureValue            float32 `json:"ApertureValue"`
	ColorSpace               int     `json:"ColorSpace"`
	CreateDate               string  `json:"CreateDate"`
	CustomRendered           int     `json:"CustomRendered"`
	DateTimeOriginal         string  `json:"DateTimeOriginal"`
	ExifImageHeight          int     `json:"ExifImageHeight"`
	ExifImageWidth           int     `json:"ExifImageWidth"`
	ExifVersion              string  `json:"ExifVersion"`
	ExposureCompensation     int     `json:"ExposureCompensation"`
	ExposureMode             int     `json:"ExposureMode"`
	ExposureProgram          int     `json:"ExposureProgram"`
	ExposureTime             float32 `json:"ExposureTime"`
	FNumber                  float32 `json:"FNumber"`
	Flash                    int     `json:"Flash"`
	FlashpixVersion          string  `json:"FlashpixVersion"`
	FocalLength              int     `json:"FocalLength"`
	FocalPlaneResolutionUnit int     `json:"FocalPlaneResolutionUnit"`
	FocalPlaneXResolution    float32 `json:"FocalPlaneXResolution"`
	FocalPlaneYResolution    float32 `json:"FocalPlaneYResolution"`
	ISO                      int     `json:"ISO"`
	InteropOffset            int     `json:"InteropOffset"`
	MeteringMode             int     `json:"MeteringMode"`
	SceneCaptureType         int     `json:"SceneCaptureType"`
	ShutterSpeedValue        float32 `json:"ShutterSpeedValue"`
	SubSecTime               string  `json:"SubSecTime"`
	SubSecTimeDigitized      string  `json:"SubSecTimeDigitized"`
	SubSecTimeOriginal       string  `json:"SubSecTimeOriginal"`
	WhiteBalance             int     `json:"WhiteBalance"`
}

type MetadataGPS

type MetadataGPS struct {
	GPSVersionID []int `json:"GPSVersionID"`
}

type MetadataImage

type MetadataImage struct {
	EXIFOffset       int    `json:"ExifOffset"`
	GPSInfo          int    `json:"GPSInfo"`
	Make             string `json:"Make"`
	Model            string `json:"Model"`
	ModifyDate       string `json:"ModifyDate"`
	Orientation      int    `json:"Orientation"`
	ResolutionUnit   int    `json:"ResolutionUnit"`
	Software         string `json:"Software"`
	XResolution      int    `json:"XResolution"`
	YCbCrPositioning int    `json:"YCbCrPositioning"`
	YResolution      int    `json:"YResolution"`
}

type MetadataInteroperability

type MetadataInteroperability struct {
	InteropIndex   string `json:"InteropIndex"`
	InteropVersion string `json:"InteropVersion"`
}

type MetadataMakernote

type MetadataMakernote struct {
}

type MetadataResponse

type MetadataResponse struct {
	Density         int                   `json:"density"`
	EXIF            *MetadataResponseEXIF `json:"exif"`
	Format          string                `json:"format"`
	HasColorProfile bool                  `json:"hasColorProfile"`
	HasTransparency bool                  `json:"hasTransparency"`
	Height          int                   `json:"height"`
	PHash           string                `json:"pHash"`
	Quality         int                   `json:"quality"`
	Size            int                   `json:"size"`
	Width           int                   `json:"width"`
}

type MetadataResponseEXIF

type MetadataResponseEXIF struct {
	EXIF             *MetadataEXIF             `json:"exif"`
	GPS              *MetadataGPS              `json:"gps"`
	Image            *MetadataImage            `json:"image"`
	Interoperability *MetadataInteroperability `json:"interoperability"`
	Makernote        *MetadataMakernote        `json:"makernote"`
	Thumbnail        *MetadataThumbnail        `json:"thumbnail"`
}

type MetadataService

type MetadataService service

MetadataService handles communication with the metadata related methods of the ImageKit API.

func (*MetadataService) GetForUploaded

func (s *MetadataService) GetForUploaded(ctx context.Context, fid string) (*MetadataResponse, error)

GetForUploaded gets image exif, pHash and other metadata for uploaded files in Imagekit.io media library using this API.

func (*MetadataService) GetFromRemote

func (s *MetadataService) GetFromRemote(ctx context.Context, URL string) (*MetadataResponse, error)

GetFromRemote gets image exif, pHash and other metadata from Imagekit.io powered remote URL using this API.

type MetadataThumbnail

type MetadataThumbnail struct {
	Compression     int `json:"Compression"`
	ResolutionUnit  int `json:"ResolutionUnit"`
	ThumbnailLength int `json:"ThumbnailLength"`
	ThumbnailOffset int `json:"ThumbnailOffset"`
	XResolution     int `json:"XResolution"`
	YResolution     int `json:"YResolution"`
}

type MoveFileRequest added in v1.1.0

type MoveFileRequest struct {
	// SourceFilePath is the full path of the file you want to copy.
	//
	// For example - /path/to/file.jpg
	SourceFilePath string `json:"sourceFilePath"`
	// DestinationPath is the full path to the folder you want to copy the above file into.
	//
	// For example - /folder/to/copy/into/
	DestinationPath string `json:"destinationPath"`
}

type MoveFolderRequest added in v1.1.0

type MoveFolderRequest struct {
	// SourceFolderPath is the full path to the source folder you want to move.
	//
	// For example - /path/of/source/folder
	SourceFolderPath string `json:"sourceFolderPath"`
	// DestinationPath is the full path to the destination folder where you want to move the source folder into.
	//
	// For example - /path/of/destination/folder/
	DestinationPath string `json:"destinationPath"`
}

type MoveFolderResponse added in v1.1.0

type MoveFolderResponse struct {
	JobID string `json:"jobId"`
}

type Options

type Options struct {
	PublicKey  string
	PrivateKey string
}

Options contains all necessary data to make requests to the API.

type PurgeCacheRequest

type PurgeCacheRequest struct {
	// URL is the exact URL of the file to be purged.
	//
	// For example - https://ik.imageki.io/your_imagekit_id/rest-of-the-file-path.jpg.
	URL string `json:"url"`
}

type PurgeCacheResponse

type PurgeCacheResponse struct {
	// RequestID which can be used to get the purge request status.
	RequestID string `json:"requestId"`
}

type PurgeCacheStatusResponse

type PurgeCacheStatusResponse struct {
	// Status is the current status of a submitted purge request.
	//
	// It can be either:
	// Pending - The request has been successfully submitted, and purging is in progress.
	// Complete - The purge request has been successfully completed. And now you should get a fresh object. Check the Age header in response to confirm this.
	Status string `json:"status"`
}

type RemoveTagsRequest added in v1.1.0

type RemoveTagsRequest struct {
	// FileIDs is the list of unique ID of the uploaded files.
	FileIDs []string `json:"fileIds"`
	// Tags is an array of tags to add on these files.
	Tags []string `json:"tags"`
}

type UpdateFileDetailsRequest

type UpdateFileDetailsRequest struct {
	// Tags associated with the file.
	Tags []string `json:"tags"`
	// CustomCoordinates define an important area in the image. This is only relevant for image type files.
	CustomCoordinates string `json:"customCoordinates"`
}

type UpdateFileDetailsResponse

type UpdateFileDetailsResponse struct {
	// FileID is the unique ID of the uploaded file.
	FileID string `json:"fileId"`
	// Type of item. It can be either file or imageFolder.
	Type string `json:"type"`
	// Name of the file or imageFolder.
	Name string `json:"name"`
	// FilePath of the file. In the case of an image, you can use this path to construct different transform.
	FilePath string `json:"filePath"`
	// Tags is array of tags associated with the image.
	Tags []string `json:"tags"`
	// IsPrivateFile is the file marked as private. It can be either "true" or "false".
	IsPrivateFile bool `json:"isPrivateFile"`
	// CustomCoordinates is the value of custom coordinates associated with the image in format "x,y,width,height".
	CustomCoordinates string `json:"customCoordinates"`
	// URL of the file.
	URL string `json:"url"`
	// Thumbnail is a small thumbnail URL in case of an image.
	Thumbnail string `json:"thumbnail"`
	// FileType of the file, it could be either image or non-image.
	FileType string `json:"fileType"`
	// MIME Type of the file.
	MIME string `json:"mime"`
	// Height of the uploaded image file.
	//
	// Only applicable when file type is image.
	Height int `json:"height"`
	// Width of the uploaded image file.
	//
	// Only applicable when file type is image.
	Width int `json:"width"`
	// Size of the uploaded file in bytes.
	Size int `json:"size"`
	// HasAlpha is whether the image has an alpha component or not.
	HasAlpha bool `json:"hasAlpha"`
	// The date and time when the file was first uploaded.
	//
	// The format is YYYY-MM-DDTHH:mm:ss.sssZ
	CreatedAt time.Time `json:"created_at"`
}

type UploadRequest

type UploadRequest struct {
	// File to upload.
	File interface{}
	// FileName with which the file has to be uploaded.
	FileName string
	// UseUniqueFileName to whether to use a unique filename for this file or not.
	UseUniqueFileName bool
	// Tags while uploading the file.
	Tags []string
	// Folder path (e.g. /images/imageFolder/) in which the image has to be uploaded. If the imageFolder(s) didn't exist before, a new imageFolder(s) is created.
	Folder string
	// IsPrivateFile to whether to mark the file as private or not. This is only relevant for image type files.
	IsPrivateFile bool
	// CustomCoordinates define an important area in the image. This is only relevant for image type files.
	CustomCoordinates string
	// ResponseFields contains values of the fields that you want ImageKit.io to return in response.
	ResponseFields []string
}

type UploadResponse

type UploadResponse struct {
	// FileID is unique.
	//
	// Store this fileld in your database, as this will be used to perform update action on this file.
	FileID string `json:"fileId"`
	// Name of the uploaded file.
	Name string `json:"name"`
	// URL of the file.
	URL string `json:"url"`
	// ThumbnailURL is a small thumbnail URL in case of an image.
	ThumbnailURL string `json:"thumbnailUrl"`
	// Height of the uploaded image file.
	//
	// Only applicable when file type is image.
	Height int `json:"height"`
	// Width of the uploaded image file.
	//
	// Only applicable when file type is image.
	Width int `json:"width"`
	// Size of the uploaded file in bytes.
	Size int `json:"size"`
	// FileType can either be "image" or "non-image".
	FileType string `json:"fileType"`
	// FilePath is the path of the file uploaded.
	//
	// It includes any imageFolder that you specified while uploading.
	FilePath string `json:"filePath"`
	// Tags is array of tags associated with the image.
	Tags []string `json:"tags"`
	// IsPrivateFile is the file marked as private.
	//
	// It can be either "true" or "false".
	IsPrivateFile bool `json:"isPrivateFile"`
	// CustomCoordinates is the value of custom coordinates associated with the image in format "x,y,width,height".
	CustomCoordinates string `json:"customCoordinates"`
	// Metadata of the upload file.
	//
	// Use responseFields property in request to get the metadata returned in response of upload API.
	Metadata interface{} `json:"metadata"`
}

type UploadService

type UploadService service

UploadService handles communication with the upload related methods of the ImageKit API.

func (*UploadService) ServerUpload

func (s *UploadService) ServerUpload(ctx context.Context, r *UploadRequest) (*UploadResponse, error)

ServerUpload uploads file to ImageKit.io.

Jump to

Keyboard shortcuts

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