File upload

Upload a file to the SFS storage space associated with particular CDN zone.

Note: Current maximum file size is 5GB

Endpoint

http://[STORAGE_SERVER_HOSTNAME]/api/v3/upload

The hostname of the storage server is the same as the FTP server listed in your dashboard.

Methods

POST

Parameters

FieldTypeDescription
zone_idintegerCDN zone ID
directorystringA folder or subfolder in which the file will be uploaded, with trailing slash. Leave empty to upload to the root folder. If a non-existing folder is entered, it will be created automatically.
upload_serverstringYour zone storage server as reported in your dashboard
api_keystringYour account's API key

Example

You must pass the file and all parameters, including your API key. Here is how to do it in PHP but you can achieve the same effect in your language of choice. For this example we will use two files - one is our actual upload function and it never changes, while the other is used to pass the parameters to the upload function and we use it dynamically in our workflow to automate the file uploading process:

class.uploader.php:


class Uploader 
    {
        var $filePath;
	    var $uploadURL;
	    var $formFileVariableName;
	    var $postParams = array ();
        
        function Uploader($filePath, $uploadURL, $formFileVariableName, $otherParams = false) 
        {
            $this->filePath = $filePath;
		    $this->uploadURL = $uploadURL;
		    if(is_array($otherParams) && $otherParams != false) 
		    {
			    foreach($otherParams as $fieldName => $fieldValue) 
			    {
				    $this->postParams[$fieldName] = $fieldValue;
			    }
		    }
		    $this->postParams[$formFileVariableName] = new \CURLFile($filePath);
	    }
        
        function UploadFile() 
	    {
		    $ch = curl_init();
            curl_setopt($ch, CURLOPT_VERBOSE, true);
		    curl_setopt($ch, CURLOPT_URL, $this->uploadURL);
            curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
		    curl_setopt($ch, CURLOPT_POST, 1);
		    curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postParams);
		    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		    $postResult = curl_exec($ch);
            echo $postResult;
		    if (curl_errno($ch)) 
		    {
			    print curl_error($ch);
			    print "Unable to upload file.";
			    exit();
		    }
		    curl_close($ch);

		    return $postResult;
	    }
    }

new_upload.php:


require_once('class.uploader.php');
$api_key = '8d4b30b60a879ff05059125e6f3md15a0728ef41'; // Your API key
$zone = '10920'; // Your CDN ID
$folder = '/apiTestUpload/'; // If empty, file is uploaded to root of the CDN zone. If the folder does not exist, it will be automatically created. Format: /folder/subfolder/
$upload_server = "http://s03.pushrcdn.com/api/v3/upload";
$upload = new Uploader('backgroundimage.jpg', $upload_server, 'file', array('api_key' => $api_key, 'zone' => $zone, 'folder' => $folder));
$result = $upload->UploadFile();

Response

HTTPJSONDescription
200{"status":"success","URL":"LINK"}File does not exist
4xx{"status":"error","description":"msg"}Upload failed due to authorization or another error. Error description is returned
520{"status":"error","description":"msg"}Upload failed due to unknown reasons. Please contact support

Important

You should always parse the returned link since special characters and white spaces will be automatically removed from the name of the uploaded file.