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
Field | Type | Description |
zone_id | integer | CDN zone ID |
directory | string | A 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_server | string | Your zone storage server as reported in your dashboard |
Headers
Field | Type | Description |
APIKEY | string | Your account 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 $apiKey;
var $postParams = array ();
function Uploader($filePath, $uploadURL, $formFileVariableName, $apiKey, $otherParams = false)
{
$this->filePath = $filePath;
$this->uploadURL = $uploadURL;
$this->apiKey = $apiKey;
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_HTTPHEADER, array('APIKEY:"'.$this->apiKey.'"'));
curl_setopt($ch, CURLOPT_URL, $this->uploadURL);
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 = "2d49e8f645d90818783c4e6c46f32ca0677dc417";
$zone = '318';
$folder = '/tesfile/folder/'; // Leave empty to upload to storage root
$upload_server = "http://s02.pushrcdn.com/api/v3/upload";
$upload = new Uploader('testfile.dat', $upload_server, 'file', $api_key , array('zone_id' => $zone, 'folder' => $folder));
$result = $upload->UploadFile();
Response
HTTP | JSON | Description |
200 | {"status":"success","URL":"LINK"} | File does not exist |
401 | {"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 |
Downloads
You can download the code examples and play with them or integrate them directly. They are production ready. Download
You should always parse the returned link since special characters and white spaces will be automatically removed from the name of the uploaded file.