10-24-2019 01:58 AM
i have this code but i can't upload file into enywhere.
can you give an example of jsonData array syntax?
i have the default installation of alfresco and i have achieved to create direcory.
i cant find the way to upload file.
thanks
<?php
//API Url
$url = '192.168.1.1:8080/alfresco/s/api/upload?alf_ticket=TICKET_e0113b837d77e99b3e0a33da110e12be52bded4e';
//Initiate cURL.
$ch = curl_init($url);
//The JSON data.
$jsonData = array(
"filedata"=> "test.txt",
"siteid"=> "siteName",
"containerid"=> "documentLibrary",
"description"=> "A shiny new node"
);
//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute the request
$result = curl_exec($ch);
?>
10-25-2019 04:21 AM
This is a working sample using the new REST API:
https://stackoverflow.com/questions/43072054/upload-files-to-alfresco-using-php-and-curl
10-27-2019 01:43 AM
thanks for your answer
but which is the relativePath?
'relativePath' => 'uploads'
10-28-2019 07:56 AM
have you done this?? is this a working example for sure?
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$url = 'http://192.168.1.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-/children?al...';
$ch = curl_init();
$charray = array(
CURLOPT_USERPWD => 'admin:admin',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'filedata' => new CURLFile('test.txt'),
'name' => 'test.txt',
'relativePath' => 'Sites/site1/documentLibrary'
),
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch,$charray);
// execute post
$result = curl_exec($ch);
// close curl handle
curl_close($ch);
?>
the above returns nothing.
Explore our Alfresco products with the links below. Use labels to filter content by product module.