Hi,I need to send a document of a Software for Alfresco. I am using this service http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-/children for create a document but i need send a file. For example: Send a PDF document to Alfresco.
What service can I consume for this?Thank you
Hi @viperboys,
I've just used Postman to upload two documents to my home directory in Alfresco.
Here is the generated PHP code from Postman:
<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-/children?alf_ticket=TICKET_53451c24e8042867a93f0d129bbd3b1f5e2a5a55", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => array('filedata'=> new CURLFILE('/Users/emay/Documents/Alfresco - a developer led strategy.pptx')), CURLOPT_HTTPHEADER => array( "Authorization: Basic dGVzdDp0ZXN0" ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
Attached you can see the files in Share.
Here's the code for uploading a jpg file:
<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-/children?alf_ticket=TICKET_53451c24e8042867a93f0d129bbd3b1f5e2a5a55", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => array('filedata'=> new CURLFILE('/Users/emay/Downloads/eddie.may.jpg')), CURLOPT_HTTPHEADER => array( "Authorization: Basic dGVzdDp0ZXN0" ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
Hopefully this should give you a start to resolving your problem.
You can use the same endpoint, but you should send your data as multipart-form-data.
Depending on your version, you can look at localhost:8080/api-explorer, or go to https://api-explorer.alfresco.com/api-explorer/#!/nodes/createNode for more info.
Thank you very much for answering ..
Can you give me a use case to do this with PHP? This is my code for create a document
<?phpset_time_limit(180);$ticket =(isset($_POST['ticket'])) ? $_POST['ticket'] : 0;$nid = (isset($_POST['name'])) ? $_POST['name'] : 0;
$data = array("name"=>"test.txt","nodeType" =>"cm:content");
$data_string = json_encode($data);
$ch = curl_init('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-/children?alf_ticket='.$ticket);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_string)));
$result = curl_exec($ch);if(curl_errno($ch) !== 0) {error_log('cURL error when connecting to ' . $url . ': ' . curl_error($ch));}
curl_close($ch);print_r($result);
?>
What do I need to add to send a document in pdf?
Sorry, I don't know PHP, you should find this answer somewhere else. The only thing I could tell you is that content-type should be multipart/form-data.
What version of PHP are you using? Also, what's the scenario where you will be using this?
Thanks,
Ok, thank you very much!
Hi, @EddieMay
I need to send a WordPress document to Alfresco. In wordpress I use a plugin called GravityForm to use form. To create the flows I use GravityFlow. The GravityFlow plugin has an add-on called WebHook for API use. At a certain step I need to send a document to Alfresco. This is the documentation https://docs.gravityflow.io/article/126-incoming-webhook
Thank you..