API Reference and Developer Documentation
Rackspace Cloud Files Integration
Kraken.io API allows you to easily store optimized images directly in your Rackspace Cloud Files (presumably CDN-enabled). With just a few additional parameters your optimized images will be pushed to Cloud Files in no time.
Mandatory Parameters: | |
user | Your Rackspace username. |
key | Your unique Cloud Files API Key. |
container | Name of a destination container on your Cloud Files account. |
Optional Parameters: | |
region | Name of the region your CloudFiles container is located in. This field is mandatory if the region is different from the default one (iad). The full list of CloudFiles regions can be found here. |
path | Destination path in your container (e.g. "images/layout/header.jpg"). Defaults to root "/". |
ssl | A boolean value (true or false ) instructing Kraken.io API to fetch either SSL or non-SSL URL from Rackspace CloudFiles. Defaults to false meaning the non-SSL URL will be returned. |
The above parameters must be passed in a cf_store
object:
{
"cf_store": {
"user": "your-rackspace-username",
"key": "your-rackspace-api-key",
"container": "destination-container"
}
}
Below you can find an example of a complete request that uses cf_store
to push optimized image into your Cloud Files 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"
},
"cf_store": {
"user": "Foobar",
"key": "12dc6c9147c201f96f20c1dcdc112919",
"container": "assets",
"path": "files/image.png"
},
"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,
"cf_store" => array(
"user" => "Foobar",
"key" => "12dc6c9147c201f96f20c1dcdc112919",
"container" => "assets",
"path" => "files/image.png"
)
);
$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,
"cf_store": {
"user": "Foobar",
"key": "12dc6c9147c201f96f20c1dcdc112919",
"container": "assets",
"path": "files/image.png"
},
};
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,
:cf_store': {
'user' => 'Foobar',
'key' => '12dc6c9147c201f96f20c1dcdc112919',
'container' => 'assets',
'path' => 'files/image.png'
}
}
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",
"cf_store": map[string]interface {} {
"user": "Foobar",
"key": "12dc6c9147c201f96f20c1dcdc112919",
"container": "assets",
"path": "files/image.png"
}
}
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"])
}
}
from krakenio import Client
api = Client('your_api_key', 'your_api_secret')
data = {
'wait': True,
'lossy': True,
'cf_store': {
'user': 'Foobar',
'key': '12dc6c9147c201f96f20c1dcdc112919',
'container': 'assets',
'path': 'files/image.png'
}
}
result = api.url('https://example.com/image.png', data);
if result.get('success'):
print(result.get('kraked_url'))
else:
print(result.get('message'))
If your container is CDN-enabled, the optimization and compression results will contain kraked_url
which points directly to the optimized file location in your Cloud Files account, for example:
https://e9ffc049726-fdd2d4f11d1005c9e8de.r2.cf1.rackcdn.com/files/image.png
If your container is not CDN-enabled kraked_url
will point to the optimized image URL in the Kraken.io API:
https://dl.kraken.io/api/ec/df/a5/c55d5668b1b5fe9e420554c4ee/header.png