Image Upload

HTTP Requests / Image Upload

On this page:
Intro ▾
{{activeSubMenu.text}} ▾
POST https://api.pixaven.com/1.0/upload
FieldDescription
fileBinary representation of the image to be processed.
dataSerialized JSON object with processing parameters.

To upload an image for processing, send a POST multipart request to https://api.pixaven.com/1.0/upload endpoint which must consist of two fields: file and data. Within the file field you must transmit binary data (an image for processing) whereas the data field is reserved for a serialized JSON object with image processing steps.

An example cURL request would look like the following:

curl https://api.pixaven.com/1.0/upload -X POST -u your-api-key: \
-F file=@/path/to/input.jpg \
-F data='{
    "resize": {
        "width": 100,
        "height": 75
    }
}'

Code Examples for Image Upload

Below, you'll find examples of how to use the Image Upload method from the Pixaven API:

<?php

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

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


/**
* Upload an image from disk, resize it to 100 x 75
* and parse the output metadata
*/

$pix
    ->upload('/path/to/input.jpg')
    ->resize(array(
        'width' => 100,
        'height' => 75
    ))
    ->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");


/**
* Upload an image from disk, resize it to 100 x 75
* and parse the output metadata
*
* Pixaven Node module enables you to provide a file path
* or a readable stream as an argument for .upload() method
*/

pix
    .upload("path/to/input.jpg")
    .resize({
        width: 100,
        height: 75
    })
    .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")


##
# Upload an image from disk, resize it to 100 x 75
# and parse the output metadata

err, meta = pix
    .upload("path/to/input.jpg")
    .resize(
        width: 100,
        height: 75
    )
    .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)
    }


    /**
    * Upload an image from disk, resize it to 100 x 75
    * and parse the output metadata
    *
    * Pixaven Golang package enables you to provide a file path
    * or an io.Reader as an argument for .Upload() method
    */

    meta, err := pix.
        Upload("path/to/input.jpg").
        Resize(pixaven.P{
            "width": 100,
            "height": 75
        }).
        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')


##
# Upload an image from disk, resize it to 100 x 75
# and parse the output metadata
#
# Pixaven Python package enables you to provide file path
# or BytesIO/cStringIO object as an argument for .upload() method

err, meta = (
    client
        .upload('path/to/input.jpg')
        .resize({
            'width': 100,
            'height': 75
        })
        .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.Upload;
import com.pixaven.Response;

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

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

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

        /**
        * Upload an image from disk, resize it to 100 x 75
        * and parse the output metadata
        */

        final Upload upload = pix.upload("path/to/input.jpg");

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

        final Response response = upload.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());
        }
    }
}

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×