File upload

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

Note: SFS has been deprecated and replaced by Sonic - PUSHR's new S3-compatible object storage service. The following SFS API is being ported to Sonic for compatibility reasons, but may become unsupported in the future. We strongly recommend that you use the S3 API instead.





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


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 
        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.";

		    return $postResult;


$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 = "";
$upload = new Uploader('backgroundimage.jpg', $upload_server, 'file', array('api_key' => $api_key, 'zone' => $zone, 'folder' => $folder));
$result = $upload->UploadFile();


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


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