uploadBase64FileData

Uploads a File into the File Manager.

uploadBase64FileData

Uploads a File into the File Manager.

Top ↑

Syntax

array uploadBase64FileData(
    string api_key,
    array file_details,
    int folder_id,
    string duplicate_action,
  [ bool skip_resize_images,
    bool skip_resample_images ] 
);

Parameters

api_key (string)

The key required to access the API. See Getting Started for more information.

file_details (array)

An associative array with the following values:

Key Type Description
name string The name to use for saving the File once it has been uploaded.
data string The file data encoded with MIME base64.
folder_id (int)

The ID of the Folder that will contain the uploaded File.

duplicate_action (string)

Action to take if a File with the same name as the upload File exists. Valid values are:

  • increment - create a new File named filename_count.jpg, where filename is the name of the original file, and count is an incremental index for Files with this filename. The first duplicate is named filename_1.jpg.
  • overwrite - overwrite the existing File with the same name.
skip_resize_images (bool - optional)

Whether or not to resize small images. Valid values are:

  • true - Do not resize images.
  • false - Resize images to a maximum value of 800px for width and 800px for height. Image ratio is kept during resizing.
skip_resample_images (bool - optional)

Whether or not to correct for lower image quality when resizing. Valid values are:

  • true - Correct for degraded image quality when resizing.
  • false - Do not correct for degraded image quality when resizing.

Return Value

Returns an array on success containing: * the ID of the uploaded File * the URL for the File

Examples

The following example uploads a File named image.png into Folder 123456. uploadBase64FileData indicates that the code should create a new File if a File with the same name exists and should not re-size the Image.

$api = new Api($url, 'YOURAPIKEY');
$file_details = array(
    'name' => 'image.png',
    'data' => base64_encode($file_contents)
);
$session_details = $api->invokeMethod('uploadBase64FileData', array($file_details , 123456, 'increment', false, false));
{
    "id": 1,
    "method": "uploadBase64FileData",
    "params": [
        "YOURAPIKEY",
        [{
             name: 'image.png',
             data: 'xcv;dlafsjlfjasl;fjsduioeuoxckvhyyf'
        }]
        123456,
        "increment",
        false,
        false
    ]
}
{
    "id": 1,
    "result": [
        1234567,
        "http:\/\/example.com\/download\/files\/00002\/1393124\/image.png"
    ],
    "error": null
}

Error Codes

This method may return the following error codes in addition to the standard error codes:

Code Error Description
360 Files cannot be empty The base64 encoded File data is empty
363 The file type is not allowed The File type is not allowed to be uploaded
364 Invalid file folder ID specified The Folder ID does not exist or does not belong to the Account
365 File not uploaded as it already exists in that folder The same File name already exists in your File Manager. You can correct this by setting duplicate_action to yes when uploading Files.
371 Internal filesystem error
372 Internal filesystem error
373 Internal filesystem error
374 Internal filesystem error
375 Internal filesystem error
376 Internal filesystem error

See Also