cancel
Showing results for 
Search instead for 
Did you mean: 

I have a issue when i try send a file to Alfresco

viperboys
Star Contributor
Star Contributor

Hi, 

I am try send a file to Alfresco.. My site web is Wordpress and i use a plugin Gravity Flow. I am creating a snippe pero this code is not work for me. This is me code 

public function process(){
// Do something here.
$entry = $this->get_entry();


$file = file_get_contents($entry['1']);
$url = 'http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-/children?alf_...';
$ch = curl_init();


curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $file );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
'Content-Disposition: form-data; filedata="Bilgais1.docx"',

] );
$result = curl_exec( $ch );
curl_close( $ch );
print_r( json_decode( $result ) );


return true;
}

I have this error 

{"error":{"errorKey":"Could not read content from HTTP request body: Unexpected character ('P' (code 80)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: java.io.BufferedReader@48162477; line: 1, column: 2]","statusCode":400,"briefSummary":"03020018 Could not read content from HTTP request body: Unexpected character ('P' (code 80)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: java.io.BufferedReader@48162477; line: 1, column: 2]","stackTrace":"Por motivos de seguridad, ya no se muestra el seguimiento de la pila, pero se guarda la propiedad para versiones anteriores.","descriptionURL":"https://api-explorer.alfresco.com"}}

I hope someone can help me. Thank you

1 ACCEPTED ANSWER

EddieMay
World-Class Innovator
World-Class Innovator

Hi @viperboys,

I've just created the following file upload.php. The code is as follows:

<?php
$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "http://localhost/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-/children?alf_ticket=TICKET_d8b9084ee020e4921687abfd0ce5a1c5ad4efd4f", 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('name' => 'Eddie May Upload','filedata'=> new CURLFILE('/Users/emay/Desktop/Test/TEST TWO.docx')), CURLOPT_HTTPHEADER => array( "Authorization: Basic dGVzdDp0ZXN0" ), )); $response = curl_exec($curl); curl_close($curl); echo $response;

The response I got from calling the file (echo $response) is:

{"entry":{"isFile":true,"createdByUser":{"id":"admin","displayName":"Administrator"},
"modifiedAt":"2020-04-06T16:08:04.943+0000","nodeType":"cm:content",
"content":{"mimeType":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"mimeTypeName":"Microsoft Word 2007","sizeInBytes":11760,"encoding":"UTF-8"},"parentId":"479ec2bc-fb73-4e93-9c44-b36d08ba0446",
"aspectNames":["cm:versionable","cm:titled","cm:auditable","cm:author"],"createdAt":"2020-04-06T16:08:04.943+0000",
"isFolder":false,"modifiedByUser":{"id":"admin","displayName":"Administrator"},
"name":"Eddie May Upload","id":"bf1ef22f-b759-4cc3-98ca-c68df911b132",
"properties":{"cm:versionLabel":"1.0","cm:author":"Eddie May",
"cm:versionType":"MAJOR"}}}

You have to make sure that your alf ticket is fresh - so you 1st need to call the login api to retrieve the ticket & add that to your curl url. Secondly, you probably need the destination noderef - here I'm just putting the file into my root.

HTH,

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

View answer in original post

6 REPLIES 6