### Clone the ImageKit iOS Quickstart Repository
Source: https://imagekit.io/docs/integration/ios
Clone the sample application from GitHub to get started with the ImageKit iOS SDK.
```bash
git clone
https://github.com/imagekit-samples/quickstart.git
```
--------------------------------
### Video Overlay Timing Example
Source: https://imagekit.io/docs/integration/javascript
Example of specifying the timing for a video overlay. Use `start` and `duration` or `start` and `end` to control when the overlay appears.
```json
{
"timing": { "start": 5, "duration": 10 }
}
```
--------------------------------
### Upload File from File System using Python
Source: https://imagekit.io/docs/api-reference/upload-file/upload-file
This Python example shows how to upload a file by reading its binary content. Ensure the 'imagekitio' library is installed.
```python
import os
from imagekitio import ImageKit
client = ImageKit(
private_key=os.environ.get("IMAGEKIT_PRIVATE_KEY")
)
# Upload file from file system
with open("image.jpg", "rb") as f:
file_data = f.read()
response = client.files.upload(
file=file_data,
file_name="my_file_name.jpg",
tags=["tag1", "tag2"]
)
print(response)
print(response.file_id)
print(response.url)
```
--------------------------------
### Example Request with DPR and Width Headers
Source: https://imagekit.io/docs/image-transformation
This example shows a GET request to ImageKit with auto DPR and width parameters, along with the Sec-CH-DPR and Sec-CH-Width headers sent by the client.
```http
GET: https://ik.imagekit.io/your_imagekitid/tr:w-auto,dpr-auto/image_name.jpg
Sec-CH-DPR: 2
Sec-CH-Width: 212
```
--------------------------------
### Get File Details using Ruby
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/get-file-details
This Ruby example uses the 'imagekitio' gem to fetch file details. Make sure the gem is installed and configured with your private API key. Replace 'file_id' with the target file's ID.
```ruby
require 'imagekitio'
client = Imagekitio::Client.new(
private_key: 'your_private_api_key'
)
result = client.files.get('file_id')
puts result
```
--------------------------------
### Upload File from File System using PHP
Source: https://imagekit.io/docs/api-reference/upload-file/upload-file
This PHP example demonstrates uploading a file by providing a file handle. Ensure the ImageKit SDK for PHP is installed.
```php
use ImageKit\ImageKit;
$public_key = "your_public_key";
$your_private_key = "your_private_key";
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
$sample_file_path = "/sample.jpg";
$imageKit = new ImageKit(
$public_key,
$your_private_key,
$url_end_point
);
// Upload Image - Binary
$uploadFile = $imageKit->uploadFile([
"file" => fopen(__DIR__."/image.jpg", "r"),
"fileName" => "my_file_name.jpg",
"tags" => ["tag1", "tag2"]
]);
echo ("Upload binary file : " . json_encode($uploadFile));
```
--------------------------------
### Create Folder using cURL (Example)
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/create-folder
An alternative cURL example for creating a folder, showing the use of basic authentication with a private key.
```shell
curl -X POST "https://api.imagekit.io/v1/folder/" \
-H 'Content-Type: application/json' \
-u your_private_key: -d \
'{ \
"folderName" : "new_folder", \
"parentFolderPath" : "source/folder/path" \
}'
```
--------------------------------
### Create URL Endpoint with Ruby
Source: https://imagekit.io/docs/api-reference/account-management-api/url-endpoints/create-url-endpoint
This Ruby example shows how to create a URL endpoint using the ImageKitio gem. Ensure you have the gem installed and your private key configured.
```ruby
require "imagekitio"
client = Imagekitio::Client.new(
private_key: "your_private_api_key"
)
result = client.accounts.url_endpoints.create(
description: "My custom URL endpoint",
url_prefix: "product-images",
origins: ["origin-id-1"]
)
puts result
```
--------------------------------
### Install npm packages for Server
Source: https://imagekit.io/docs/integration/ios
Navigate to the Server folder and install npm packages required for the backend.
```bash
cd Server/
npm install
```
--------------------------------
### Get Bulk Job Status using ImageKit Go SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/bulk-job-status
This Go example demonstrates how to get the status of a bulk job. Initialize the ImageKit client with your private key and use the Folders.Job.Get method.
```Go
import (
"context"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
client := imagekit.NewClient(
option.WithPrivateKey("your_private_key"),
)
response, err := client.Folders.Job.Get(context.TODO(), "job_id")
if err != nil {
panic(err.Error())
}
```
--------------------------------
### Install ImageKit Video Player SDK
Source: https://imagekit.io/docs/integration/javascript
Use npm to install the Video Player SDK. This is the first step to integrating the player into your project.
```bash
npm install @imagekit/video-player
```
--------------------------------
### Installation
Source: https://imagekit.io/docs/integration/javascript
Instructions for installing the ImageKit JavaScript SDK using npm, yarn, or a script tag.
```APIDOC
## Installation
Install the SDK via npm or yarn:
```
npm install @imagekit/javascript
# or
yarn add @imagekit/javascript
```
You can also include the SDK directly in your HTML using a script tag. It is recommended to load a specific version to avoid unexpected breaking changes:
```html
```
For environments with module bundlers (e.g., webpack, Rollup) or ES modules, simply import the functions:
```javascript
import { buildSrc, buildTransformationString, upload, getResponsiveImageAttributes } from '@imagekit/javascript';
```
```
--------------------------------
### Dynamic SEO Suffix URL Example
Source: https://imagekit.io/docs/seo-friendly-url
This example shows how to construct a URL with a dynamic SEO suffix using the 'ik-seo' parameter. It demonstrates the transformation from a standard URL to an SEO-friendly one.
```text
https://ik.imagekit.io/demo/ik-seo/DSC1234/eiffel-tower.jpg
```
--------------------------------
### Install iOS Project Dependencies
Source: https://imagekit.io/docs/integration/ios
Navigate to the cloned repository and install the necessary dependencies using CocoaPods.
```bash
cd quickstart/ios/
pod install
```
--------------------------------
### Delete Multiple Files using Ruby SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/delete-multiple-files
This Ruby example shows how to initialize the ImageKit client and delete multiple files. Ensure you have the 'imagekitio' gem installed.
```ruby
require 'imagekitio'
client = Imagekitio::Client.new(
private_key: 'your_private_api_key'
)
result = client.files.bulk.delete(
file_ids: ["file_id_1", "file_id_2"]
)
puts result
```
--------------------------------
### Get File Metadata using cURL
Source: https://imagekit.io/docs/api-reference/file-metadata/get-metadata-from-url
This command-line example shows how to fetch file metadata using cURL. Replace 'your_private_api_key' with your actual private API key.
```bash
curl -X GET "https://api.imagekit.io/v1/metadata?url=https://ik.imagekit.io/demo/tr:w-100/default-image.jpg" \
-u your_private_api_key:
```
--------------------------------
### Subtitle Overlay Example
Source: https://imagekit.io/docs/integration/javascript
Example of configuring a subtitle overlay with custom font size and color. Ensure the input is a valid subtitle file.
```json
{
"type": "subtitle",
"input": "my-subtitle.vtt",
"transformation": [
{ "fontSize": 20, "fontColor": "FF0000" }
]
}
```
--------------------------------
### Video Overlay Example
Source: https://imagekit.io/docs/integration/javascript
Example of configuring a video overlay with specified dimensions. The input path is relative to your ImageKit media library.
```json
{
"type": "video",
"input": "overlay-video.mp4",
"transformation": [
{ "width": 100, "height": 100 }
]
}
```
--------------------------------
### Solid Color Overlay Example
Source: https://imagekit.io/docs/integration/javascript
Example of configuring a solid color overlay with specified dimensions and color. Use RGB/RGBA hex codes or color names.
```json
{
"type": "solidColor",
"color": "FF0000",
"transformation": [
{ "width": 100, "height": 100 }
]
}
```
--------------------------------
### Text Overlay Example
Source: https://imagekit.io/docs/integration/javascript
Example of configuring a text overlay with custom font size and color. Ensure the text content is URL-safe or use appropriate encoding.
```json
{
"type": "text",
"text": "ImageKit",
"transformation": [
{ "fontSize": 20, "fontColor": "FF0000" }
]
}
```
--------------------------------
### Image Overlay Example
Source: https://imagekit.io/docs/integration/javascript
Example of configuring an image overlay with specified dimensions. The input path is relative to your ImageKit media library.
```json
{
"type": "image",
"input": "logo.png",
"transformation": [
{ "width": 100, "height": 100 }
]
}
```
--------------------------------
### Move Folder cURL Example
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/move-folder
This is an alternative cURL example for moving a folder, demonstrating the use of basic authentication with your private key.
```shell
curl -X POST "https://api.imagekit.io/v1/bulkJobs/moveFolder" \
-H 'Content-Type: application/json' \
-u your_private_key: -d \
'{ \
"sourceFolderPath" : "/folder/to/move", \
"destinationPath" : "/folder/to/move/into/" \
}'
```
--------------------------------
### Create Folder using Go SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/create-folder
Demonstrates creating a folder with the ImageKit Go SDK. Initialize the client with your private key and handle potential errors.
```go
import (
"context"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
client := imagekit.NewClient(
option.WithPrivateKey("your_private_key"),
)
response, err := client.Folders.New(context.TODO(), imagekit.FolderNewParams{
FolderName: "new_folder",
ParentFolderPath: "source/folder/path",
})
if err != nil {
panic(err.Error())
}
```
--------------------------------
### Create Folder using Ruby SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/create-folder
This Ruby example shows folder creation with the ImageKit SDK. Initialize the client with your private key.
```ruby
require 'imagekitio'
client = Imagekitio::Client.new(
private_key: 'your_private_api_key'
)
result = client.folders.create(
folder_name: 'new_folder',
parent_folder_path: 'source/folder/path'
)
puts result
```
--------------------------------
### Install JavaScript SDK via npm or yarn
Source: https://imagekit.io/docs/integration/javascript
Install the ImageKit JavaScript SDK using npm or yarn package managers.
```bash
npm install @imagekit/javascript
# or
yarn add @imagekit/javascript
```
--------------------------------
### Account Usage Response Example
Source: https://imagekit.io/docs/api-reference/account-management-api/get-usage
This is an example of the JSON response structure for account usage data, including bandwidth, storage, and processing units.
```json
{
"bandwidthBytes": 21991583578,
"mediaLibraryStorageBytes": 1878758298,
"videoProcessingUnitsCount": 0,
"extensionUnitsCount": 0,
"originalCacheStorageBytes": 0
}
```
--------------------------------
### Overlay Position Example
Source: https://imagekit.io/docs/integration/javascript
Example of setting the position of an overlay using x and y coordinates or a focus point. Coordinates are relative to the base asset.
```json
{
"position": { "x": 10, "y": 20 }
}
```
```json
{
"position": { "focus": "center" }
}
```
--------------------------------
### Run the backend app
Source: https://imagekit.io/docs/integration/ios
Start the Node.js backend server.
```bash
node index.js
```
--------------------------------
### Get Purge Status with Go SDK
Source: https://imagekit.io/docs/api-reference/caching/purge-status
This Go example shows how to get the purge cache status using the ImageKit Go SDK. Initialize the client with your private key and use the Get method with the request ID.
```go
package main
import (
"context"
"fmt"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
func main() {
client := imagekit.NewClient(
option.WithPrivateKey("your_private_api_key"),
)
// request_id is the requestId returned in response of purge cache API
result, err := client.Cache.Invalidation.Get(context.TODO(), "request_id")
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", result)
// Print the purge cache status
fmt.Printf("Cache status: %s\n", result.Status)
}
```
--------------------------------
### Copy File using cURL (Example)
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/copy-file
An alternative cURL example for copying a file, demonstrating the use of `-u` for basic authentication and `-d` for the request body.
```shell
curl -X POST "https://api.imagekit.io/v1/files/copy" \
-H 'Content-Type: application/json' \
-u your_private_key: -d \
'{ \
"sourceFilePath" : "/path/to/file.jpg", \
"destinationPath" : "/folder/to/copy/into/", \
"includeFileVersions" : true \
}'
```
--------------------------------
### Example: Uploading a file with basic parameters
Source: https://imagekit.io/docs/integration/javascript
Demonstrates a basic file upload using the required parameters like file, fileName, signature, token, expire, and publicKey.
```javascript
upload({
file: fileInput.files[0],
fileName: "myImage.jpg",
signature: "generated_signature",
token: "unique_upload_token",
expire: 1616161616,
publicKey: "your_public_api_key"
});
```
--------------------------------
### Example cURL Request for Saved Extensions
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/saved-extensions/list-extensions
This cURL example shows how to fetch saved extensions using the ImageKit API. It includes the GET method, URL, and authorization header.
```shell
curl -X GET "https://api.imagekit.io/v1/saved-extensions" \
-H 'Content-Type: application/json' \
-u your_private_key:
```
--------------------------------
### Get File Metadata with Java
Source: https://imagekit.io/docs/api-reference/file-metadata/get-uploaded-file-metadata
Use the ImageKit Java SDK to get file metadata. This example shows a direct method call to retrieve metadata for a given fileId.
```java
ResultMetaData result = ImageKit.getInstance().getFileMetadata("file_id");
```
--------------------------------
### Get File Version Details using Ruby SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/get-file-version-details
This Ruby example shows how to get file version details using the ImageKit Ruby SDK. It requires your private API key.
```ruby
require 'imagekitio'
client = Imagekitio::Client.new(
private_key: 'your_private_api_key'
)
result = client.files.versions.get(
'version_id',
file_id: 'file_id'
)
puts result
```
--------------------------------
### Upload File from File System using Go
Source: https://imagekit.io/docs/api-reference/upload-file/upload-file
This Go example demonstrates uploading a file from a file path. Ensure the 'imagekit-go' SDK is imported.
```go
import (
"context"
"os"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
client := imagekit.NewClient(
option.WithPrivateKey("your_private_key"),
)
file, err := os.Open("/Users/username/Desktop/my_file_name.jpg")
if err != nil {
panic(err.Error())
}
deferr file.Close()
response, err := client.Files.Upload(context.TODO(), imagekit.FileUploadParams{
File: file,
FileName: "my_file_name.jpg",
})
if err != nil {
panic(err.Error())
}
```
--------------------------------
### Get File Metadata from URL (Go)
Source: https://imagekit.io/docs/api-reference/file-metadata/get-metadata-from-url
This Go example shows how to get file metadata from a URL using the ImageKit Go SDK. It includes error handling and prints specific metadata fields.
```go
package main
import (
"context"
"fmt"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
func main() {
client := imagekit.NewClient(
option.WithPrivateKey("your_private_api_key"),
)
result, err := client.Files.Metadata.GetFromURL(context.TODO(), imagekit.FileMetadataGetFromURLParams{
URL: "https://ik.imagekit.io/demo/tr:w-100/default-image.jpg",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", result)
// Print the file metadata fields
fmt.Printf("Width: %d\n", result.Width)
if result.Exif.JSON.Image.Valid {
fmt.Printf("X Resolution: %+v\n", result.Exif.Image.XResolution)
}
}
```
--------------------------------
### Move Folder using ImageKit Go SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/move-folder
This Go example shows how to move a folder using the ImageKit Go SDK. It initializes the client with your private key and uses FolderMoveParams.
```go
import (
"context"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
client := imagekit.NewClient(
option.WithPrivateKey("your_private_key"),
)
response, err := client.Folders.Move(context.TODO(), imagekit.FolderMoveParams{
SourceFolderPath: "/folder/to/move",
DestinationPath: "/folder/to/move/into/",
})
if err != nil {
panic(err.Error())
}
```
--------------------------------
### Create Folder using Node.js SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/create-folder
This Node.js example demonstrates creating a folder using the ImageKit SDK. Initialize the client with your private key.
```javascript
import ImageKit from '@imagekit/nodejs';
const client = new ImageKit({
privateKey: "your_private_api_key"
});
try {
const result = await client.folders.create({
folderName: "new_folder",
parentFolderPath: "source/folder/path"
});
console.log(result);
} catch (error) {
console.log(error);
}
```
--------------------------------
### Get Account Usage with Node.js SDK
Source: https://imagekit.io/docs/api-reference/account-management-api/get-usage
Fetch account usage data using the ImageKit Node.js SDK. Initialize the client with your private API key and call the get method with start and end dates.
```javascript
import ImageKit from '@imagekit/nodejs';
const client = new ImageKit({
privateKey: "your_private_api_key"
});
try {
const result = await client.accounts.usage.get({
startDate: "2023-04-01",
endDate: "2023-04-30"
});
console.log(result);
} catch (error) {
console.log(error);
}
```
--------------------------------
### Get File Details using Python
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/get-file-details
This Python example shows how to get file details using the ImageKit Python SDK. It retrieves the private key from environment variables. Replace 'file_id' with the actual file ID.
```python
import os
from imagekitio import ImageKit
client = ImageKit(
private_key=os.environ.get("IMAGEKIT_PRIVATE_KEY")
)
response = client.files.get("file_id")
print(response)
print(response.file_id)
```
--------------------------------
### Get Purge Status with PHP SDK
Source: https://imagekit.io/docs/api-reference/caching/purge-status
This PHP example shows how to get the purge cache status using the ImageKit PHP SDK. You need to provide your public key, private key, and URL endpoint for initialization.
```php
use ImageKit\ImageKit;
$public_key = "your_public_api_key";
$your_private_key = "your_private_api_key";
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
$imageKit = new ImageKit(
$public_key,
$your_private_key,
$url_end_point
);
// The requestId returned in the response of purge cache API.
$requestId = 'request_id';
$purgeCacheStatus = $imageKit->purgeCacheApiStatus("request_id");
echo("Purge cache status : " . json_encode($purgeCacheStatus));
```
--------------------------------
### Add Tags (Bulk) using Go SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/add-tags-bulk
This Go example demonstrates adding tags to multiple files using the ImageKit Go SDK. It initializes the client with your private key and uses `imagekit.FileBulkAddTagsParams`.
```go
import (
"context"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
client := imagekit.NewClient(
option.WithPrivateKey("your_private_key"),
)
response, err := client.Files.Bulk.AddTags(context.TODO(), imagekit.FileBulkAddTagsParams{
FileIDs: []string{"file_id_1", "file_id_2"},
Tags: []string{"tag1", "tag2"},
})
if err != nil {
panic(err.Error())
}
```
--------------------------------
### GET /v1/accounts/usage
Source: https://imagekit.io/docs/api-reference/account-management-api/get-usage
Fetches account usage information for a specified date range. The response includes data from the start date up to, but not including, the end date. The difference between start and end dates must be less than 90 days.
```APIDOC
## GET /v1/accounts/usage
### Description
Get the account usage information between two dates. Note that the API response includes data from the start date while excluding data from the end date. In other words, the data covers the period starting from the specified start date up to, but not including, the end date.
### Method
GET
### Endpoint
https://api.imagekit.io/v1/accounts/usage
### Parameters
#### Query Parameters
- **startDate** (string) - Required - Specify a `startDate` in `YYYY-MM-DD` format. It should be before the `endDate`. The difference between `startDate` and `endDate` should be less than 90 days.
- **endDate** (string) - Required - Specify a `endDate` in `YYYY-MM-DD` format. It should be after the `startDate`. The difference between `startDate` and `endDate` should be less than 90 days.
### Request Example
```json
{
"startDate": "YYYY-MM-DD",
"endDate": "YYYY-MM-DD"
}
```
### Response
#### Success Response (200)
- **bandwidthBytes** (integer) - Amount of bandwidth used in bytes.
- **mediaLibraryStorageBytes** (integer) - Storage used by media library in bytes.
- **videoProcessingUnitsCount** (integer) - Number of video processing units used.
- **extensionUnitsCount** (integer) - Number of extension units used.
- **originalCacheStorageBytes** (integer) - Storage used by the original cache in bytes.
#### Response Example
```json
{
"bandwidthBytes": 21991583578,
"mediaLibraryStorageBytes": 1878758298,
"videoProcessingUnitsCount": 0,
"extensionUnitsCount": 0,
"originalCacheStorageBytes": 0
}
```
```
--------------------------------
### Get Saved Extension Details (Go)
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/saved-extensions/get-extension
This Go example illustrates how to get saved extension details using the ImageKit Go SDK. Remember to replace 'your_private_api_key' with your actual private API key and 'ext_abc123' with the extension ID.
```go
package main
import (
"context"
"fmt"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
func main() {
client := imagekit.NewClient(
option.WithPrivateKey("your_private_api_key"),
)
savedExtension, err := client.SavedExtensions.Get(context.TODO(), "ext_abc123")
if err != nil {
panic(err.Error())
}
fmt.Println(savedExtension)
}
```
--------------------------------
### Get Purge Status with JavaScript (Browser)
Source: https://imagekit.io/docs/api-reference/caching/purge-status
This JavaScript example demonstrates how to get the purge cache status in a browser environment using the ImageKit JS SDK. Initialize the SDK with your public key, private key, and URL endpoint.
```javascript
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
ResultCacheStatus resultCacheStatus = imagekit.PurgeStatus("request_Id");
```
--------------------------------
### Retrieve URL-endpoint using ImageKit Go SDK
Source: https://imagekit.io/docs/api-reference/account-management-api/url-endpoints/get-url-endpoint
This Go example shows how to initialize the ImageKit client with your private key and retrieve a URL-endpoint. It includes error handling and demonstrates accessing specific details from the response.
```go
package main
import (
"context"
"fmt"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
func main() {
client := imagekit.NewClient(
option.WithPrivateKey("your_private_api_key"),
)
result, err := client.Accounts.URLEndpoints.Get(context.TODO(), "url_endpoint_id")
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", result)
// Access URL endpoint details
fmt.Printf("Endpoint ID: %s\n", result.ID)
fmt.Printf("Description: %s\n", result.Description)
fmt.Printf("URL Prefix: %s\n", result.URLPrefix)
}
```
--------------------------------
### Create S3 Origin with Go SDK
Source: https://imagekit.io/docs/api-reference/account-management-api/origins/create-origin
This Go example demonstrates creating an S3 origin using the ImageKit Go SDK. It utilizes context and specific option functions for configuration.
```go
package main
import (
"context"
"fmt"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
func main() {
client := imagekit.NewClient(
option.WithPrivateKey("your_private_api_key"),
)
result, err := client.Accounts.Origins.New(context.TODO(), imagekit.AccountOriginNewParams{
OriginRequest: imagekit.OriginRequestUnionParam{
OfS3: &imagekit.OriginRequestS3Param{
Name: "My S3 Origin",
Bucket: "test-bucket",
AccessKey: "AKIATEST123",
SecretKey: "secrettest123",
Prefix: imagekit.String("images"),
},
},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", result)
}
```
--------------------------------
### Get Bulk Job Status using ImageKit Node.js SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/bulk-job-status
This Node.js example shows how to fetch the status of a bulk job using the ImageKit SDK. Initialize the ImageKit client with your private key and call the get method with the jobId.
```JavaScript
import ImageKit from '@imagekit/nodejs';
const client = new ImageKit({
privateKey: "your_private_key"
});
try {
const jobId = "job_id";
const result = await client.folders.job.get(jobId);
console.log(result);
} catch (error) {
console.log(error);
}
```
--------------------------------
### Get Thumbnail from Specific Time Point
Source: https://imagekit.io/docs/create-video-thumbnails
Use the 'so' parameter to specify the start offset in seconds for capturing the thumbnail from a video.
```url
https://ik.imagekit.io/demo/img/60cd.mp4/ik-thumbnail.jpg?tr=so-5
```
--------------------------------
### Open Xcode Workspace
Source: https://imagekit.io/docs/integration/ios
Open the Xcode workspace to run the sample application after installing dependencies.
```bash
open ImagekitDemo.xcodeworkspace
```
--------------------------------
### Get File Version Details using Java
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/get-file-version-details
Example of retrieving file version details in Java. This code requires the fileId and versionId to be specified.
```java
String fileId = "file_id";
String versionId = "version_id";
ResultFileVersionDetails resultFileVersionDetails = ImageKit.getInstance().getFileVersionDetails(fileId, versionId);
```
--------------------------------
### Filter Textarea Custom Metadata
Source: https://imagekit.io/docs/api-reference/upload-file/upload-file
Filter files based on a Textarea custom metadata field. This example selects files where 'description' starts with 'Ontario'.
```text
"request.customMetadata.description" : "Ontario"
```
--------------------------------
### Create URL Endpoint with Go
Source: https://imagekit.io/docs/api-reference/account-management-api/url-endpoints/create-url-endpoint
This Go example demonstrates creating a URL endpoint using the ImageKit Go SDK. It utilizes context for API calls and handles potential errors.
```go
package main
import (
"context"
"fmt"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
func main() {
client := imagekit.NewClient(
option.WithPrivateKey("your_private_api_key"),
)
result, err := client.Accounts.URLEndpoints.New(context.TODO(), imagekit.AccountURLEndpointNewParams{
URLEndpointRequest: imagekit.URLEndpointRequestParam{
Description: "My custom URL endpoint",
URLPrefix: imagekit.String("product-images"),
Origins: []string{"origin-id-1"},
},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", result)
}
```
--------------------------------
### ImageKit.io URL with Transformation as Query Parameter
Source: https://imagekit.io/docs/integration/web-proxy
This example shows how to apply transformations, like resizing to 300x300 pixels, using query parameters in the ImageKit.io URL.
```text
https://ik.imagekit.io/your_imagekit_id/https://www.example.com/rest-of-the-path.jpg?tr=w-300,h-300
```
--------------------------------
### Example: Uploading with progress tracking
Source: https://imagekit.io/docs/integration/javascript
Shows how to use the onProgress callback to monitor the upload status, receiving loaded and total bytes.
```javascript
onProgress: (event) => console.log(event.loaded, event.total)
```
--------------------------------
### Upload File from File System using Node.js
Source: https://imagekit.io/docs/api-reference/upload-file/upload-file
This Node.js example demonstrates uploading a file using a readable stream. Make sure to install the '@imagekit/nodejs' package.
```javascript
import ImageKit from '@imagekit/nodejs';
import fs from 'fs';
const client = new ImageKit({
privateKey: "your_private_key"
});
try {
const result = await client.files.upload({
file: fs.createReadStream('image.jpg'), //required
fileName: "my_file_name.jpg", //required
tags: ["tag1", "tag2"]
});
console.log(result);
} catch (error) {
console.log(error);
}
```
--------------------------------
### Basic Image Resizing Example
Source: https://imagekit.io/docs/image-transformation
Demonstrates how to resize an image to a specific width using the 'w-' transformation parameter. This is a common use case for adapting images to different display requirements.
```URL
https://ik.imagekit.io/ikmedia/tr:w-200/docs_images/examples/example_fashion_1.jpg
```
--------------------------------
### List Saved Extensions (Ruby)
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/saved-extensions/list-extensions
This Ruby example uses the 'imagekitio' gem to list saved extensions. Ensure you have the gem installed and replace 'your_private_api_key' with your actual key.
```ruby
require 'imagekitio'
client = Imagekitio::Client.new(
private_key: 'your_private_api_key'
)
saved_extensions = client.saved_extensions.list
puts saved_extensions
```
--------------------------------
### Create Folder using Python SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/create-folder
Example of creating a folder with the ImageKit Python SDK. It's recommended to load your private key from environment variables.
```python
import os
from imagekitio import ImageKit
client = ImageKit(
private_key=os.environ.get("IMAGEKIT_PRIVATE_KEY")
)
response = client.folders.create(
folder_name="new_folder",
parent_folder_path="source/folder/path"
)
print(response)
```
--------------------------------
### Get Origin by ID (cURL - Alternative)
Source: https://imagekit.io/docs/api-reference/account-management-api/origins/get-origin
An alternative cURL example for retrieving origin details, specifying the content type and using basic authentication with your private key.
```shell
curl -X GET "https://api.imagekit.io/v1/accounts/origins/{id}" \
-H 'Content-Type: application/json' \
-u your_private_key:
```
--------------------------------
### Create Folder using C# SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/create-folder
This C# example shows folder creation using the ImageKit SDK. It requires initializing the ImageKit client and creating a CreateFolderRequest object.
```csharp
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
CreateFolderRequest createFolderRequest = new CreateFolderRequest
{
folderName = "new_folder",
parentFolderPath = "source/folder/path"
};
ResultEmptyBlock resultEmptyBlock = imagekit.CreateFolder(createFolderRequest);
```
--------------------------------
### Get File Metadata from Remote URL (PHP)
Source: https://imagekit.io/docs/api-reference/file-metadata/get-metadata-from-url
Retrieve file metadata from a remote URL using the ImageKit PHP SDK. This example directly calls the SDK method.
```php
$imageKit->getFileMetadataFromRemoteURL("https://ik.imagekit.io/demo/tr:w-100/default-image.jpg")
```
--------------------------------
### ImageKit.io URL with Transformation as Path Parameter
Source: https://imagekit.io/docs/integration/web-proxy
This example demonstrates how to apply transformations, such as resizing to 300x300 pixels, directly within the ImageKit.io URL path.
```text
https://ik.imagekit.io/your_imagekit_id/tr:w-300,h-300/https://www.example.com/rest-of-the-path.jpg
```
--------------------------------
### Upload Base64 Encoded File with Tags using Node.js
Source: https://imagekit.io/docs/api-reference/upload-file/upload-file
This Node.js example demonstrates uploading a base64 encoded string as a file, including tags. Ensure the '@imagekit/nodejs' package is installed.
```javascript
import ImageKit from '@imagekit/nodejs';
const client = new ImageKit({
privateKey: "your_private_api_key"
});
const base64Img = "iVBORw0KGgoAAAAN";
try {
const result = await client.files.upload({
file: base64Img, //required
fileName: "my_file_name.jpg", //required
tags: ["tag1","tag2"]
});
console.log(result);
} catch (error) {
console.log(error);
}
```
--------------------------------
### Copy File using ImageKit Go SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/copy-file
Example of copying a file using the ImageKit Go SDK. This snippet demonstrates initializing the client and making the copy request.
```go
import (
"context"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
client := imagekit.NewClient(
option.WithPrivateKey("your_private_key"),
)
response, err := client.Files.Copy(context.TODO(), imagekit.FileCopyParams{
SourceFilePath: "/path/to/file.jpg",
DestinationPath: "/folder/to/copy/into/",
IncludeFileVersions: imagekit.Bool(false), // optional
})
if err != nil {
panic(err.Error())
}
```
--------------------------------
### Authentication Example
Source: https://imagekit.io/docs/api-overview
Demonstrates how to authenticate API requests using your private API key via Basic Auth.
```APIDOC
## Authentication
ImageKit.io API requests are authenticated using your account's private API key via HTTP Basic Auth. Provide your private API key as the username and leave the password empty.
### Method
All API requests must be made over HTTPS.
### Example using curl with private API key
```bash
curl https://api.imagekit.io/v1/files \
-u your_private_api_key:
```
### Example using Authorization header
Encode your private API key followed by a colon (e.g., `your_private_api_key:`) using Base64.
```bash
curl https://api.imagekit.io/v1/files \
-H 'Authorization: Basic '
```
**Note:** The colon (`:`) after the private key is required for correct authentication.
```
--------------------------------
### Get Bulk Job Status using ImageKit Java SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-folders/bulk-job-status
This Java example retrieves the status of a bulk job. It requires initializing the ImageKit instance and calling getBulkJobStatus with the jobId.
```Java
String jobId = "job_id";
ResultBulkJobStatus resultBulkJobStatus = ImageKit.getInstance().getBulkJobStatus(jobId);
```
--------------------------------
### Delete Multiple Files using Node.js SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/delete-multiple-files
This Node.js example shows how to initialize the ImageKit client and use the bulk delete files method. Ensure you have the '@imagekit/nodejs' package installed.
```javascript
import ImageKit from '@imagekit/nodejs';
const client = new ImageKit({
privateKey: "your_private_api_key"
});
try {
const result = await client.files.bulk.delete({
fileIds: ["file_id_1","file_id_2"]
});
console.log(result);
} catch (error) {
console.log(error);
}
```
--------------------------------
### Get Purge Status with Node.js SDK
Source: https://imagekit.io/docs/api-reference/caching/purge-status
This Node.js example demonstrates how to retrieve the purge cache status using the ImageKit SDK. Ensure you have initialized the ImageKit client with your private key.
```javascript
import ImageKit from '@imagekit/nodejs';
const client = new ImageKit({
privateKey: "your_private_api_key"
});
try {
const result = await client.cache.invalidation.get("request_id");
console.log(result);
} catch (error) {
console.log(error);
}
```
--------------------------------
### ImageKit.io URL Structure Example
Source: https://imagekit.io/docs/integration/web-server
This illustrates the structure of an ImageKit.io URL, including the URL endpoint, transformations, and the file path. It shows how ImageKit.io internally fetches files from a configured web server origin.
```text
https://ik.imagekit.io/your_imagekit_id/tr:w-300,h-300/rest-of-the-path.jpg
```
--------------------------------
### Get Saved Extension Details (Ruby)
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/saved-extensions/get-extension
This Ruby example demonstrates fetching saved extension details with the ImageKit.io Ruby gem. Substitute 'your_private_api_key' with your key and 'ext_abc123' with the extension's ID.
```ruby
require 'imagekitio'
client = Imagekitio::Client.new(
private_key: 'your_private_api_key'
)
saved_extension = client.saved_extensions.get("ext_abc123")
puts saved_extension
```
--------------------------------
### Add Tags (Bulk) using Ruby SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/add-tags-bulk
This Ruby example shows how to add tags to multiple files using the ImageKit Ruby gem. Initialize the client with your private key.
```ruby
require 'imagekitio'
client = Imagekitio::Client.new(
private_key: 'your_private_api_key'
)
result = client.files.bulk.add_tags(
file_ids: [
"file_id_1",
"file_id_2"
],
tags: [
"tag1",
"tag2"
]
)
puts result
```
--------------------------------
### Get File Version Details using Python SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/get-file-version-details
Retrieve file version details with the Python SDK. This example uses environment variables for the private key and requires the fileId and versionId.
```python
import os
from imagekitio import ImageKit
client = ImageKit(
private_key=os.environ.get("IMAGEKIT_PRIVATE_KEY")
)
file_versions_details = client.files.versions.get("version_id", file_id="file_id")
print("Get File version details:", file_versions_details)
# print that file's id
print(file_versions_details.file_id)
# print that file's version id
print(file_versions_details.version_info.id)
```
--------------------------------
### Get File Version Details using Node.js SDK
Source: https://imagekit.io/docs/api-reference/digital-asset-management-dam/managing-assets/get-file-version-details
This Node.js example shows how to retrieve file version details using the ImageKit SDK. It requires your private API key for authentication.
```javascript
import ImageKit from '@imagekit/nodejs';
const client = new ImageKit({
privateKey: "your_private_api_key"
});
try {
const result = await client.files.versions.get("version_id", {
fileId: "file_id"
});
console.log(result);
} catch (error) {
console.log(error);
}
```
--------------------------------
### Create S3 Origin with Node.js SDK
Source: https://imagekit.io/docs/api-reference/account-management-api/origins/create-origin
This Node.js example shows how to create an S3 origin using the ImageKit SDK. Make sure to install the SDK and provide your private API key.
```javascript
import ImageKit from '@imagekit/nodejs';
const client = new ImageKit({
privateKey: "your_private_api_key"
});
try {
const result = await client.accounts.origins.create({
name: "My S3 Origin",
type: "S3",
bucket: "test-bucket",
prefix: "images",
accessKey: "AKIATEST123",
secretKey: "secrettest123"
});
console.log(result);
} catch (error) {
console.log(error);
}
```
--------------------------------
### Get Account Usage with Go SDK
Source: https://imagekit.io/docs/api-reference/account-management-api/get-usage
Retrieve account usage metrics using the ImageKit Go SDK. Initialize the client with your private key and provide start and end dates for the query.
```go
package main
import (
"context"
"fmt"
"time"
"github.com/imagekit-developer/imagekit-go/v2"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
func main() {
client := imagekit.NewClient(
option.WithPrivateKey("your_private_api_key"),
)
// Get usage for the last 30 days
endDate := time.Now()
startDate := endDate.AddDate(0, 0, -30) // 30 days ago
result, err := client.Accounts.Usage.Get(context.TODO(), imagekit.AccountUsageGetParams{
StartDate: startDate,
EndDate: endDate,
})
if err != nil {
panic(err.Error())
}
fmt.Printf("Bandwidth: %d bytes\n", result.BandwidthBytes)
fmt.Printf("Storage: %d bytes\n", result.MediaLibraryStorageBytes)
}
```
--------------------------------
### List URL Endpoints (Ruby)
Source: https://imagekit.io/docs/api-reference/account-management-api/url-endpoints/list-url-endpoints
This Ruby example demonstrates fetching URL endpoints using the ImageKit SDK. Initialize the client with your private API key.
```ruby
require "imagekitio"
client = Imagekitio::Client.new(
private_key: "your_private_api_key"
)
result = client.accounts.url_endpoints.list
puts result
```
--------------------------------
### Get Account Usage with Python SDK
Source: https://imagekit.io/docs/api-reference/account-management-api/get-usage
Retrieve account usage details using the ImageKit Python SDK. Initialize the client with your private key and specify start and end dates for the query.
```python
import os
from datetime import date
from imagekitio import ImageKit
client = ImageKit(
private_key=os.environ.get("IMAGEKIT_PRIVATE_KEY")
)
result = client.accounts.usage.get(
start_date=date(2023, 4, 1),
end_date=date(2023, 4, 30)
)
print(result)
print(f"Bandwidth: {result.bandwidth_bytes} bytes")
print(f"Storage: {result.media_library_storage_bytes} bytes")
```