Optidash CDN - Overview

Optidash CDN / Overview

On this page:

The Optidash API is a fully-featured image processing platform. It uses a volatile storage to store processed images for you to download back and serve on your websites and applications. However, on top the API you can optionally add our premium add-on "Storage and Delivery". Once enabled, all your optimized images will be pushed to a secure Cloud Storage and delivered to your end-user with blazing speed over a 65+ Tbps global network.

By default, when you have "Storage and Delivery" enabled on your account, the API will detect that fact and always give you a public CDN URL within the response body that you can use in production right away:

{
    "url": "https://acme.optidash.net/49ba8413-ac8a-41e0-8bc0-00387e8e5aa4/image.jpg"
}

Disabling Optidash CDN on Per-Request Basis

There are times when you do not want a particular image (or set of images) to be pushed to the CDN when you have "Storage and Delivery" enabled. In order to instruct the API to ignore the CDN completely, simply set "push": false with the cdn hash in your request. That way you'll receive a volatile storage URL in the response body and that particular image will not be available on the CDN.

{
    "cdn": {
        "push": false
    }
}

A full JSON request which ignores the CDN would look like the following (with cURL):

curl https://api.optidash.ai/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
    },
    "cdn": {
        "push": false
    }
}'

Code Examples for Optidash CDN

Below, you'll find examples of how to control Optidash CDN from the Optidash API:

  • PHP
  • Node
  • Ruby
  • Go
  • Python
  • Java
<?php

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

$opti = new Optidash\Optidash('your-api-key');


/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 100 x 75 and ignore the CDN for that particular request
*/

$opti
    ->fetch('https://www.website.com/image.jpg')
    ->resize(array(
        'width' => 100,
        'height' => 75
    ))
    ->cdn(array(
        'push' => false
    ))
    ->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 Optidash = require("optidash");


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

const opti = new Optidash("your-api-key");


/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 100 x 75 and ignore the CDN for that particular request
*/

opti
    .fetch("https://www.website.com/image.jpg")
    .resize({
        width: 100,
        height: 75
    })
    .cdn({
        push: false
    })
    .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 "optidash"


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

opti = Optidash.new("your-api-key")


##
# Provide a publicly available image URL with fetch(string) method,
# resize the image to 100 x 75 and ignore the CDN for that particular request

err, meta = opti
    .fetch("https://www.website.com/image.jpg")
    .resize(
        width: 100,
        height: 75
    )
    .cdn(
        push: false
    )
    .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/optidash/optidash-go"
)

func main() {

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

    opti, err := optidash.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 ignore the CDN for that particular request
    */

    meta, err := opti.
        Fetch("https://www.website.com/image.jpg").
        Resize(optidash.P{
            "width": 100,
            "height": 75
        }).
        Cdn(optidash.P{
            "push": false,
        }).
        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 optidash import optidash


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

opti = optidash('your-api-key')


##
# Provide a publicly available image URL with fetch(string) method,
# resize the image to 100 x 75 and ignore the CDN for that particular request

err, meta = (
    opti
        .fetch('https://www.website.com/image.jpg')
        .resize({
            'width': 100,
            'height': 75
        })
        .cdn({
            'push': False
        })
        .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.optidash.examples;

/**
* Import dependencies
*/

import static com.optidash.OperationConfiguration.settings;
import com.optidash.Optidash;
import com.optidash.Response;

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

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

        Optidash opti = new Optidash("your-api-key");

        /**
        * Provide a publicly available image URL with fetch(string) method,
        * resize the image to 100 x 75 and ignore the CDN for that particular request
        */

        final Fetch fetch = opti.fetch("https://www.website.com/image.jpg");

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

        fetch.cdn(
            settings()
                .set("push", false)
        );

        final Response response = fetch.toJson();

        /**
        * You'll find the full JSON metadata hash within the `Response#getMetadata()` property.
        * 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());
        }
    }
}
Grace Przemek Magda Damian
Have questions? Let's talk!We usually respond in just under an hour

Thanks for reaching out!

We've received your message
and will get to it as quickly as possible.

Whoops, looks like something went wrong.

We encountered an unexpected error and cannot complete your request. Please try reloading the page.