API Reference and Developer Documentation

Microsoft Azure Integration

Kraken.io API allows you to store optimized images directly in your Micorsoft Azure Blob Storage. With just a few additional parameters your optimized images will be pushed to Microsoft Azure in no time.

Mandatory Parameters:
accountYour Azure Storage Account.
keyYour unique Azure Storage Access Key.
containerName of a destination container on your Azure account.
Optional Parameters:
pathDestination path in your container (e.g. "images/layout/header.jpg"). Defaults to root "/".
metadataAzure Blob Metadata you would like to assign to your Azure Blob (optimized image) formatted as key-value pairs.
headersAny custom headers you would like to pass along with your Azure Blob (optimized image). Supported headers are Content-Type, Content-Encoding, Content-Language, Content-Disposition and Cache-Control

The above parameters must be passed in a azure_store object:

{
    "azure_store": {
        "account": "your-azure-account",
        "key": "your-azure-key",
        "container": "destination-container",
        "headers": {
            "Cache-Control": "public, max-age=31536000"
        }
    }
}

Below you can find an example of a complete JSON request that uses azure_store to push optimized image into your Microsoft Azure container. We will use url option to feed the API with a URL of image to be optimized. The below request uses example (fake) credentials - you will need to replace them with your real ones.

{
    "auth": {
        "api_key": "your_api_key",
        "api_secret": "your_api_secret"
    },
    "azure_store": {
        "account": "foobar",
        "key": "M3mmbjOlIZr11OZoULqUWyFA1EpOdZAEcmaC64E/Ft9MRfDEYE7qDJm+9ezGQY15==",
        "container": "assets",
        "path": "files/image.png",
        "headers": {
            "Cache-Control": "public, max-age=31536000"
        }
    },
    "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,
    "azure_store" => array(
        "account" => "foobar",
        "key" => "M3mmbjOlIZr11OZoULqUWyFA1EpOdZAEcmaC64E/Ft9MRfDEYE7qDJm+9ezGQY15==",
        "container" => "assets",
        "path" => "files/image.png",
        "headers" => array(
            "Cache-Control" => "public, max-age=31536000"
        )
    )
);

$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,
    "lossy": true,
    "azure_store": {
        "account": "foobar",
        "key": "M3mmbjOlIZr11OZoULqUWyFA1EpOdZAEcmaC64E/Ft9MRfDEYE7qDJm+9ezGQY15==",
        "container": "assets",
        "path": "files/image.png",
        "headers": {
            "Cache-Control": "public, max-age=31536000"
        }
    }
};

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,
    :lossy => true,
    :azure_store => {
        'account' => 'foobar',
        'key' => 'M3mmbjOlIZr11OZoULqUWyFA1EpOdZAEcmaC64E/Ft9MRfDEYE7qDJm+9ezGQY15==',
        'container' => 'assets',
        'path' => 'files/image.png',
        'headers' => {
            'Cache-Control' => 'public, max-age=31536000'
        }
    }
}

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,
        "lossy": true,
        "url": "https://example.com/image.png",
        "azure_store": map[string]interface {} {
            "account": "foobar",
            "key": "M3mmbjOlIZr11OZoULqUWyFA1EpOdZAEcmaC64E/Ft9MRfDEYE7qDJm+9ezGQY15==",
            "container": "assets",
            "path": "files/image.png",
            "headers": map[string]interface {} {
                "Cache-Control": "public, max-age=31536000"
            }
        }
    }

    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.Azure;
using OptimizeWaitRequest = Kraken.Model.Azure.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")
        {
            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,
    'azure_store': {
        'account': 'foobar',
        'key': 'M3mmbjOlIZr11OZoULqUWyFA1EpOdZAEcmaC64E/Ft9MRfDEYE7qDJm+9ezGQY15==',
        'container': 'assets',
        'path': 'files/image.png',
        'headers': {
            'Cache-Control' => 'public, max-age=31536000'
        }
    }
}

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 Microsoft Azure Containter, for example:

https://foobar.blob.core.windows.net/assets/images/layout/header.jpg