API Reference and Developer Documentation
Amazon S3 Integration
Kraken.io API allows you to store optimized images directly in your S3 bucket. With just a few additional parameters your optimized images will be pushed to S3 in no time.
If you're using a custom bucket policy and restricting actions that could be performed on the bucket's objects be sure to add
"s3:PutObjectAcl"
in the actions
parameter in your bucket policy.Mandatory Parameters: | |
key | Your unique Amazon "Access Key ID" |
secret | Your unique Amazon "Secret Access Key" |
bucket | Name of a destination bucket on your Amazon S3 account |
region | Name of the region your S3 bucket is located in. This field is mandatory if the region is different from the default one (us-east-1). The full list of S3 regions can be found here. |
Optional Parameters: | |
path | Destination path in your S3 bucket (e.g. "images/layout/header.jpg"). Defaults to root "/" |
acl | Permissions of a destination object. This can be "public_read" or "private". Defaults to "public_read" |
metadata | S3 Metadata you would like to assign to your S3 object (optimized image) |
headers | Any custom headers you would like to pass along with your S3 object (optimized image). See example below for proper formatting |
tags | Any custom tags you would like to assign to your S3 object. Up to ten tags can be applied per object. See below JSON example. |
The above parameters must be passed in a s3_store
object:
{
"s3_store": {
"key": "your_amazon_access_key",
"secret": "your-amazon-secret-key",
"bucket": "destination-bucket",
"region": "your-s3-bucket-location"
}
}
Below you can find an example of a complete JSON request that uses s3_store
to push optimized image into your S3 bucket. We will use the url
option to feed the API with the URL of the image to be optimized. Note: You must replace the example credentials given below with your own.
{
"auth": {
"api_key": "your_api_key",
"api_secret": "your_api_secret"
},
"s3_store": {
"key": "your_amazon_access_key",
"secret": "your_amazon_secret_key",
"bucket": "destination_bucket",
"path": "files/image.png",
"region": "your_s3_bucket_location",
"tags": {
"tag1": "my-first-tag",
"tag2": "my-second-tag"
}
},
"url": "https://example.com/image.png",
"wait": true,
"lossy": true
}
<?php
require_once("Kraken.php");
$kraken = new Kraken("your_api_key", "your_api_secret");
$params = array(
"url" => "https://example.com/image.png",
"wait" => true,
"lossy" => true,
"s3_store" => array(
"key" => "your_amazon_access_key",
"secret" => "your_amazon_secret_key",
"bucket" => "assets",
"path" => "files/image.png",
"region" => "your_s3_bucket_location"
)
);
$data = $kraken->url($params);
if ($data["success"]) {
echo "Success. Optimized image URL: " . $data["kraked_url"];
} else {
echo "Fail. Error message: " . $data["message"];
}
var Kraken = require("kraken");
var kraken = new Kraken({
"api_key": "your_api_key",
"api_secret": "your_api_secret"
});
var params = {
"url": "https://example.com/image.png",
"wait": true,
"s3_store": {
"key": "your_amazon_access_key",
"secret": "your_amazon_secret_key",
"bucket": "destination_bucket",
"path": "files/image.png",
"region": "your_s3_bucket_location"
}
};
kraken.url(params, function (status) {
if (status.success) {
console.log("Success. Optimized image URL: %s", status.kraked_url);
} else {
console.log("Fail. Error message: %s", status.message);
}
});
require 'rubygems'
require 'kraken-io'
kraken = Kraken::API.new(
:api_key => 'your_api_key',
:api_secret => 'your_api_secret'
)
params = {
:wait => true,
:s3_store => {
'key' => 'your_amazon_access_key',
'secret' => 'your_amazon_secret_key',
'bucket' => 'assets',
'path' => 'files/image.png',
'region' => 'your_s3_bucket_location'
}
}
data = kraken.url('https://example.com/image.png', params)
if data.success
puts 'Success! Optimized image URL: ' + data.kraked_url
else
puts 'Fail. Error message: ' + data.message
end
package main
import (
"log"
"github.com/kraken-io/kraken-go"
)
func main() {
kr, err := kraken.New("your_api_key", "your_api_secret")
if err != nil {
log.Fatal(err)
}
params := map[string]interface {} {
"wait": true,
"url": "https://example.com/image.png",
"s3_store": map[string]interface {} {
"key": "your_amazon_access_key",
"secret": "your_amazon_secret_key",
"bucket": "destination_bucket",
"path": "files/image.png",
"region": "your_s3_bucket_location"
}
}
data, err := kr.URL(params)
if err != nil {
log.Fatal(err)
}
if data["success"] != true {
log.Println("Failed, error message ", data["message"])
} else {
log.Println("Success, Optimized image URL: ", data["kraked_url"])
}
}
using Kraken;
using Kraken.Http;
using Kraken.Model.S3;
using OptimizeWaitRequest = Kraken.Model.S3.OptimizeWaitRequest;
var connection = Connection.Create("your_api_key", "your_api_secret");
var client = new Client(connection);
var response = client.OptimizeWait(new OptimizeWaitRequest(
new Uri("https://example.com/image.png"), "account", "key", "container", "region")
{
Lossy = true
});
if (response.Result.StatusCode == HttpStatusCode.OK) {
var url = response.Result.Body.KrakedUrl;
}
from krakenio import Client
api = Client('your_api_key', 'your_api_secret')
data = {
'wait': True,
'lossy': True,
's3_store': {
'key': 'your_amazon_access_key',
'secret': 'your_amazon_secret_key',
'bucket": "destination_bucket",
'path': 'files/image.png',
'region': 'your_s3_bucket_location'
}
}
result = api.url('https://example.com/image.png', data);
if result.get('success'):
print(result.get('kraked_url'))
else:
print(result.get('message'))
The optimization and compression results will contain a kraked_url
property which points directly to the optimized file location in your Amazon S3 bucket, for example:
https://s3.amazonaws.com/destination_bucket/files/image.png