I need to send a document of a Software for Alfresco

cancel
Showing results for 
Search instead for 
Did you mean: 
viperboys
Active Member II

I need to send a document of a Software for Alfresco

Jump to solution

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

1 Solution

Accepted Solutions
EddieMay
Alfresco Employee

Re: I need to send a document of a Software for Alfresco

Jump to solution

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.

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!

View solution in original post

16 Replies
narkuss
Established Member II

Re: I need to send a document of a Software for Alfresco

Jump to solution

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. 

viperboys
Active Member II

Re: I need to send a document of a Software for Alfresco

Jump to solution

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

<?php
set_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_...);
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?

narkuss
Established Member II

Re: I need to send a document of a Software for Alfresco

Jump to solution

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.

EddieMay
Alfresco Employee

Re: I need to send a document of a Software for Alfresco

Jump to solution

Hi @viperboys,

What version of PHP are you using? Also, what's the scenario where you will be using this?

Thanks, 

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
viperboys
Active Member II

Re: I need to send a document of a Software for Alfresco

Jump to solution

Ok, thank you very much!

viperboys
Active Member II

Re: I need to send a document of a Software for Alfresco

Jump to solution

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.. 

EddieMay
Alfresco Employee

Re: I need to send a document of a Software for Alfresco

Jump to solution

Hi @viperboys,

There's this library  - there's a discussion here about utilising this library, which is an implementation of Apache Chemistry CMIS. There is an example php upload file here, with usage instructions, for another approach.

HTH,

 

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
viperboys
Active Member II

Re: I need to send a document of a Software for Alfresco

Jump to solution

Hi @EddieMay 

Thank you very much .. This has helped me a lot.

Finally .. What service can I use to create a document and that its contents are metadata of the form? And if there is any use case to use it in POSTMAN.

EddieMay
Alfresco Employee

Re: I need to send a document of a Software for Alfresco

Jump to solution

Hi @viperboys,

Postman - I use it to manually test api calls, easier than debugging Alfresco, etc. Here are two introductions -1, 2.  

The Alfresco call will look something like this:

http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root?objectId=d140f140-2701-4ca6-8a80-8cdc9cd3b72c&cmisaction=createDocument&propertyId[0]=cmis:name&propertyValue[0]=ThirdPartyFormApigee.jpg&propertyId[1]=cmisSmiley SurprisedbjectTypeId&propertyValue[1]=cmis:document&alf_ticket=TICKET_3375c54fb50e6251d9e57f696483708ff9cc653a

obectid=d140f140-2701-4ca6-8a80-8cdc9cd3b72c = the destination folder id 

The thing to note with CMIS is that you're actually creating a new document in Alfresco - hence you need  to pass the content stream - in effect the document you're uploading is created as a new document in Alfresco.

Another thing to note is Apache Chemistry CMIS implementation does not support versioning - or at least as far as I can tell. However, this StackOverflow mentions it may be possible using a different library.

HTH,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!