Rackspace Cloud Files

External Storage / Rackspace Cloud Files

On this page:
Intro ▾
{{activeSubMenu.text}} ▾

In order to use Rackspace Cloud Files as your External Storage of choice, you must set the provider attribute to rackspace within the store hash and, at a minimum, provide your Rackspace credentials (username and key) as well as a container name and Rackspace region used. The full list of store hash attibutes for Rackspace Cloud Files can be found below.

Your container must be CDN-enabled in order for the Pixaven API to fetch the publicly available image URL.
store hash attributes for Rackspace Cloud Files:
AttributeTypeRequiredDescription
providerStringYesprovider must be set to rackspace.
usernameStringYesYour Rackspace Username.
keyStringYesYour Rackspace API Key.
containerStringYesName of a destination container in your Rackspace Cloud Files account.
regionStringYesName of the Rackspace region in which your container is located. Can be one of the following: iad, dfw, hkg and syd
pathStringNoDestination path in your Cloud Files container (without leading slash). Defaults to root.
secureBooleanNoWhether or not the Pixaven API should fetch SSL or non-SSL URL from Rackspace Cloud Files. Defaults to true
{
    "store": {
        "provider": "rackspace",
        "username": "rackspace-username",
        "key": "cloud-files-api-key",
        "region": "iad",
        "container": "images",
        "path": "assets/image.jpg",
        "secure": true
    }
}

An example cURL request of using Rackspace Cloud Files as the External Storage provider will look like the following:

curl https://api.pixaven.com/1.0/fetch -X POST -u your-api-key: \
-H "Content-Type: application/json" \
-d '{
    "url": "https://www.website.com/image.jpg",
    "resize": {
        "width": 100,
        "height": 75
    },
    "store": {
        "provider": "rackspace",
        "username": "rackspace-username",
        "key": "cloud-files-api-key",
        "region": "iad",
        "container": "images",
        "path": "assets/image.jpg",
        "secure": true
    }
}'

When using Rackspace Cloud Files as your External Storage, the url property within the JSON response will point to the object’s location within the Cloud Files container and you can safely use that URL in production, for example:

HTTP/1.1 200 OK

Date: {{now}}
Status: 200 OK
Content-Type: application/json

{
    "success": true,
    "code": 200,
    "id": "9cdd1db7-2b7d-41b6-bf54-6da932398405",
    "input": {
        "name": "image.jpg",
        ..
    },
    "output": {
        "url": "https://3bbb915602b5d-9f49e449aa2d09aed832d3aa.ssl.cf5.rackcdn.com/assets/image.jpg",
        ..
    }
}

Code Examples for Rackspace Cloud Files External Storage

Below, you'll find examples of how to use Rackspace Cloud Files from the Pixaven API:

<?php

/**
* Instantiate new `$pix` by calling a constructor
*/

$pix = new Pixaven\Pixaven('your-api-key');


/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 100 x 75 and store it in Rackspace Cloud Files
*/

$pix
    ->fetch('https://www.website.com/image.jpg')
    ->resize(array(
        'width' => 100,
        'height' => 75
    ))
    ->store(array(
        'provider' => 'rackspace',
        'username' => 'rackspace-username',
        'key' => 'cloud-files-api-key',
        'region' => 'iad',
        'container' => 'images',
        'path' => 'assets/image.jpg',
        'secure' => true
    ))
    ->toJSON(function ($error, $meta) {
        if (!empty($error)) {
            throw new Exception($error);
        }

        /**
        * You'll find the full JSON metadata array within the `$meta` variable.
        * Remember to always check if the `success` property is set to `true`.
        */

        if ($meta['success'] == true) {
            print ($meta['output']['url']);
        } else {
            print ($meta['message']);
        }
    });
/**
* Module dependencies
*/

const Pixaven = require("pixaven");


/**
* Instantiate new `pix` by calling a constructor
*/

const pix = new Pixaven("your-api-key");


/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 100 x 75 and store it in Rackspace Cloud Files
*/

pix
    .fetch("https://www.website.com/image.jpg")
    .resize({
        width: 100,
        height: 75
    })
    .store({
        provider: "rackspace",
        username: "rackspace-username",
        key: "cloud-files-api-key",
        region: "iad",
        container: "images",
        path: "assets/image.jpg",
        secure: true
    })
    .toJSON((err, meta) => {
        if (err) {
            return console.log(err);
        }

        /**
        * You'll find the full JSON metadata hash within the `meta` variable.
        * Remember to always check if the `success` property is set to `true`.
        */

        if (meta.success) {
            console.log(meta.output.url);
        } else {
            console.log(meta.message);
        }
    });
##
# Require dependencies

require "pixaven"


##
# Instantiate new `pix` by calling a constructor

pix = Pixaven.new("your-api-key")


##
# Provide a publicly available image URL with fetch(string) method,
# resize the image to 100 x 75 and store it in Rackspace Cloud Files

err, meta = pix
    .fetch("https://www.website.com/image.jpg")
    .resize(
        width: 100,
        height: 75
    )
    .store(
        provider: "rackspace",
        username: "rackspace-username",
        key: "cloud-files-api-key",
        region: "iad",
        container: "images",
        path: "assets/image.jpg",
        secure: true
    )
    .to_json

abort(err) if err


##
# You'll find the full JSON metadata hash within the `meta` variable.
# Remember to always check if the `success` property is set to `true`.

if meta["success"]
    puts meta["output"]["url"]
else
    puts meta["message"]
end
package main

import (
    "fmt"
    "github.com/pixaven/pixaven-go"
)

func main() {

    /**
    * Instantiate new `pix` by calling a constructor
    */

    pix, err := pixaven.NewClient("your-api-key")

    if err != nil {
        panic(err)
    }


    /**
    * Provide a publicly available image URL with Fetch(string) method,
    * resize the image to 100 x 75 and store it in Rackspace Cloud Files
    */

    meta, err := pix.
        Fetch("https://www.website.com/image.jpg").
        Resize(pixaven.P{
            "width": 100,
            "height": 75
        }).
        Store(pixaven.P{
            "provider": "rackspace",
            "username": "rackspace-username",
            "key": "cloud-files-api-key",
            "region": "iad",
            "container": "images",
            "path": "assets/image.jpg",
            "secure": true
        }).
        ToJSON()

    if err != nil {
        panic(err)
    }


    /**
    * You'll find the full JSON metadata hash within the `meta` variable.
    * Remember to always check if the `success` property is set to `true`.
    */

    if meta["success"].(map[string]interface{})["success"].(bool) {
        fmt.Println(meta["output"].(map[string]interface{})["url"])
    } else {
        fmt.Println(meta["message"])
    }
}
##
# Import dependencies

from pixaven import pixaven


##
# Instantiate new `client` by calling a constructor

client = pixaven('your-api-key')


##
# Provide a publicly available image URL with fetch(string) method,
# resize the image to 100 x 75 and store it in Rackspace Cloud Files

err, meta = (
    client
        .fetch('https://www.website.com/image.jpg')
        .resize({
            'width': 100,
            'height': 75
        })
        .store({
            'provider': 'rackspace',
            'username': 'rackspace-username',
            'key': 'cloud-files-api-key',
            'region': 'iad',
            'container': 'images',
            'path': 'assets/image.jpg',
            'secure': True
        })
        .toJSON()
)

if err is not None:
    raise StandardError(err)


##
# You'll find the full JSON metadata hash within the `meta` variable.
# Remember to always check if the `success` property is set to `true`.

if meta['success'] is True:
    print (meta['output']['url'])
else:
    print (meta['message'])
package com.pixaven.examples;

/**
* Import dependencies
*/

import static com.pixaven.OperationConfiguration.settings;
import com.pixaven.Pixaven;
import com.pixaven.Fetch;
import com.pixaven.Response;

public class StorageRackspace {
    public static void main(String[] args) {

        /**
        * Instantiate new `pix` by calling a constructor
        */

        Pixaven pix = new Pixaven("your-api-key");

        /**
        * Provide a publicly available image URL with fetch(string) method,
        * resize the image to 100 x 75 and store it in Rackspace Cloud Files
        */

        final Response response = pix.fetch("https://www.website.com/image.jpg");

        fetch.resize(
            settings()
                .set("width", 100)
                .set("height", 75)
        );

        fetch.store(
            settings()
                .set("provider", "rackspace")
                .set("key", "cloud-files-api-key")
                .set("username", "rackspace-username")
                .set("region", "iad")
                .set("container", "images")
                .set("path", "assets/image.jpg")
                .set("secure", true)
        );

        final Response response = fetch.toJson();

        /**
        * You'll find the full JSON metadata hash within the `Response#getMetadata()` variable.
        * Remember to always check if the `Response#successful` property is set to `true`.
        */

        if (response.isSuccessful()) {
            System.out.println(response.getMetadata().getOutput().get("url"));
        } else {
            System.out.println(response.getMessage());
        }
    }
}

We use both proprietary and third-party cookies to improve your browsing experience and to provide you with a better service. By continuing to use this site you consent our use of cookies as described in our Cookie Policy×