Hello,
I would like to upload file in Alfresco using the REST API /alfresco/service/api/upload but I have always an error 500 with this message (06250305 Unexpected error occurred during upload of new content)
This is my code :
$destinationNodeRef = $this->getNodeRef($destinationPath);
$type = "image/jpeg";
$cfile = new CURLFile($filePath, $type);
$curl = new Curl();
$response = $curl->post(
$this->_alfUrl . '/alfresco/service/api/upload?alf_ticket=' . $_SESSION['alf_token'], array(
'filedata' => $cfile,
'contenttype' => "cm:content",
'fileName' => $fileName,
'destination' => $destinationNodeRef,
'nodeRef' => $destinationNodeRef
)
);
$destinationNodeRef is something like : workspace://SpacesStore/f8f2fcb5-b64f-47f7-9b1c-f95b85460a58
If someone could help me, it would be marvelous
Thanks
C.
Hello,
I cannot send you all the code it's too big. But I can add this part. It's the function called to upload the file on my php server (it works, the file is uploaded in the directory UPLOAD_DIR).
function uploadContent($file, $nodeRef, $filenameAlf) {
$alfresco = new Alfresco(ALFRESCO_URL, "http://localserver.com/");
if ($alfresco->validSession() && $this->checkPermission(CUSTOMER)) {
$filename = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$destination = UPLOAD_DIR . $filename;
move_uploaded_file($_FILES['file']['tmp_name'], $destination);
$fileToUpload = $destination; //.$_FILES['file']['tmp_name'];
$res = $alfresco->uploadFile($fileToUpload, $filenameAlf, $nodeRef, $type );
return new Response('', 200);
}
return new Response('Unauthorized', 401);
}
and my function uploadFile in the class Alfresco (for the moment I only work with picture, so I initialize the type with "image/jpeg").
public function uploadFile($filePath, $fileName, $destinationPath, $type) {
if (empty($filePath)) {
return false;
}
if (empty($fileName)) {
return false;
}
if (empty($destinationPath)) {
return false;
}
$destinationNodeRef = $this->getNodeRef($destinationPath);
$type = "image/jpeg";
$cfile = new CURLFile($filePath, $type);
$curl = new Curl();
$response = $curl->post(
$this->_alfUrl . '/alfresco/service/api/upload?alf_ticket=' . $_SESSION['alf_token'], array(
'filedata' => $cfile,
'contenttype' => "cm:content",
'type' => "cm:content",
'fileName' => $fileName,
'destination' => $destinationNodeRef,
'nodeRef' => $destinationNodeRef
)
);
return $response->headers['Status-Code'] == 200;
}
Thank you for your help
C.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.