AnsweredAssumed Answered

Help me convert Postman to PHP CURL

Question asked by coisox on Apr 9, 2018
Latest reply on Apr 10, 2018 by coisox

I've tried so much codes found on the internet but can't get it to work. Maybe due to different Alfresco version or PHP version, I don't know.

 

I successfully upload new file through POSTMAN. Now I want to upload file using Dropzone.js and pass it to PHP file.

 

Here's my POSTMAN:

 

When uploading using Dropzone.js, the PHP file receive the file through $_FILES. Here's the var_dump($_FILES):

array(5)
{
  ["name"] => string(12)"contacts.csv"
  ["type"] => string(24)"application/vnd.ms-excel"
  ["tmp_name"] => string(14)"/tmp/phpGJagTg"
  ["error"] => int(0)
  ["size"] => int(2767)
}

 

Here're two of my latest codes that are not working:

CODE 1:

$data = http_build_query(array(
"filedata" => $_FILES["file"]["tmp_name"],
"destination" => "workspace://SpacesStore/$myNodeRef",
"uploadDirectory" => "p",
"description" => "",
"contenttype" => "cm:content",
"overwrite" => "true",
"thumbnails" => "doclib"
));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$alfrescoUrl/alfresco/service/api/upload?alf_ticket=$ticket");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = json_decode(curl_exec($ch), true);
echo var_dump($result);

 

CODE 2:

Note that dropzone.css is located on same folder as the php file which received the upload.

$data = "
  filedata=dropzone.css
  &destination=workspace://SpacesStore/$myNodeRef
  &uploadDirectory=p
  &description=
  &contenttype=cm:content
  &overwrite=true
  &thumbnails=doclib
"
;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$alfrescoUrl/alfresco/service/api/upload?alf_ticket=$ticket");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = json_decode(curl_exec($ch), true);
echo var_dump($result);

Outcomes