Reputation: 13
I am trying to add content to Adobe's CQ5 DAM with the REST APIs from PHP. Wondering if there are any examples of this, because I am struggling to figure it out.
Upvotes: 1
Views: 1923
Reputation: 9304
Following function will upload an image using PUT method, which is enough to add new asset to DAM.
function uploadFile($url, $login, $password, $filePath) {
$name = basename($filePath);
$fp = fopen($filePath, 'r');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url/$name");
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($filePath));
$result = curl_exec($ch);
curl_close($ch);
fclose($fp);
return $result;
}
Sample usage:
uploadFile('http://localhost:4502/content/dam/geometrixx',
'admin',
'admin',
'my-picture.jpg');
it will create new DAM asset under /content/dam/geometrixx/my-picture.jpg
.
Upvotes: 3