AnsweredAssumed Answered

creating web assets with WCM REST API

Question asked by kb9zzw on Nov 10, 2009
Latest reply on Nov 21, 2011 by bigobigo
I'm trying to figure out how to create / upload a file in a WCM sandbox using the WCM REST API for Alfresco 3.2.  I'm using PHP/cURL as my client.  I've been able to create an asset using a JSON post to the following API:

Create a new WCM asset.
POST /alfresco/service/api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}/assets/{path}

However, I'm at a loss to figure out how to upload a file instead of dropping string content into the "content" JSON field.  Documentation suggests the following for the "content" input value:

    optional, string content of the new file, this is a convenience method, normally content is added via the file upload which gives greater control over the content.

I'm at a loss to understand what file upload mechanism is needed.  Perhaps someone can look at my sample code and suggest how this might be changed to accommodate a file upload?

Sample PHP / cURL code:


# Web project and sandbox

# Define Asset
$path = "www/avm_webapps/ROOT/";
$asset = '{ name:"sample.txt",type:"file",content:"this is a sample text file" }';

# Service API
$api = "http://localhost:8080/alfresco/service/api/wcm/webprojects/$webproject/sandboxes/$sandbox/assets/$path";

# Create asset
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_USERPWD,"username:password");
curl_setopt($ch,CURLOPT_HTTPHEADER, array("Content-Type:application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $asset);

$data = curl_exec($ch);