File Handling in the SoftLayer API

From SoftLayer Development Network Wiki

Jump to: navigation, search

At times the SoftLayer API requires users to send files to it (attaching files to tickets, for instance) and frequently returns file data upon request (retrieving invoice PDF's and bandwidth graphs, for instance). SoftLayer accepts and returns file data using Base64 MIME encoding. Base64 encoding preserves data integrity for XML-based RPC transactions, and is easily decoded to raw binary data by most major programing and scripting languages. File data in the SoftLayer API is presented in the SOAP Base64binary and XML-RPC base64 data types.

Sending Files to the API

Use the SoftLayer_Container_Utility_File_Attachment container data type if you need to send file data to the API. A method's wiki page states if it requires a file attachment container parameter.

A note about XML-RPC base64 data in PHP

Currently, PHP does not have native support for sending XML-RPC using the base64 data type. Raw file contents are passed through PHP as the string data type. To force PHP to send the base64 data type in an XML-RPC call define a stdClass object with two properties:

  1. scalar containing the raw file data you wish to send to the SoftLayer API and
  2. xmlrpc_type set to the string "base64"

$myFile = new stdClass();
$myFile->scalar = file_get_contents('/path/to/myfile');
$myFile->xmlrpc_type = 'base64';

The xmlrpc_type property instructs PHP's XML-RPC encoding functions to encapsulate your file data in <base64> tags. Use this structure in the data portion of any SoftLayer_Container_Utility_File_Attachment objects you need to send to our API. Likewise, decoded base64 XML-RPC call results are sent back to PHP as one of these stdClass objects.

See Also

External Links

Personal tools