
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 08:00 AM
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):
{
["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:
"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.
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);
- Labels:
-
Alfresco Content Services
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 09:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 08:31 AM
I don't use PHP anymore, but when using curl in bash scripts, I have to use a '@' as prefix for the filepath to let curl know that filedata is a filename and not the content of the file.
Have you tried (for example) filedata=@dropzone.css or "filedata"=>"@" . $_FILES... ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 08:58 AM
I've tried these two as your suggestion but fail:
$data = http_build_query(array('filedata' => "@"."dropzone.css", ...));
$data = array('filedata' => "@"."dropzone.css", ...);
Got this error:
An error inside the HTTP server which prevented it from fulfilling the request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 09:35 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 07:29 PM
Yes. i have look at it. His $_FILES is same as me but his approach seems totally different. He include "Alfresco/Service/xxx" library which I didn't. I successfully login and create new folder without "Alfresco/Service/xxx". I'm trying to do this:
File upload | Alfresco Documentation
Which didn't suggest me to use "Alfresco/Service/xxx"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 09:55 PM
I don't know whats happening when all replies gone missing (Can I even delete replied message?). Anyway, I found the solution after being lead by your URL suggestion. I thank you for all your help Martin Ehe
Here the final code:
$_FILES["file"]["tmp_name"],
$_FILES["file"]["type"],
$_FILES["file"]["name"]
);
$data = array(
"filedata" => $cfile,
"destination" => "workspace://SpacesStore/$myNodeRef",
"uploadDirectory" => "subfolder",
"description" => "",
"contenttype" => "cm:content",
"overwrite" => "true",
"thumbnails" => "doclib"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$myAlfrescoUrl/alfresco/service/api/upload?alf_ticket=$myTicket");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
if($result["nodeRef"]) {
echo "\n\nUpload success. NodeRef: ".$result["nodeRef"];
}
else {
echo "\n\nUpload error: ".$result["message"];
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2019 03:23 AM
could you pls send the whole code for this?
thanks
