AnsweredAssumed Answered

File Upload, Node Content Empty

Question asked by oweno on Jan 4, 2010
Latest reply on Jul 8, 2017 by gmasand09
I am using a simple PHP script to test file upload service.  Works great on my localhost (Ubuntu 9.04 / Alfresco 3.2, community), but on another server (Windows, Alfresco 3.1.1 enterprise), the node gets created fine with correct name, description, etc, but the node content is empty (no file).    wondering if its a problem with the version, 3.2  vs 3.1

   trying to figure out what is going wrong, nothing in logs, no exceptions thrown. Both Alfresco installs (my local, and remote windows) are vanilla, and share only a few customizations.

// Include the required Alfresco PHP API objects 
require_once 'Alfresco/Service/WebService/WebServiceFactory.php';
require_once 'Alfresco/Service/Repository.php';
require_once 'Alfresco/Service/SpacesStore.php';
require_once "Alfresco/Service/Session.php";

$timestamp = time();

// Specify the connection details
// this works:
//$repositoryURL = "http://localhost:8080/alfresco/api";
//$userName = "admin";
//$password = "admin";

// this doesn't work,  node is created, but node content is empty
$repositoryURL = "https://<windows remote machine>:8443/alfresco/api";
$userName = "admin";
$password = "admin";

// Authenticate the user and create a session
$repository = new Repository($repositoryURL);
$ticket = $repository->authenticate($userName, $password);
$session = $repository->createSession($ticket);

// Create a reference to the 'SpacesStore'
$spacesStore = new SpacesStore($session);

$nodes = $session->query($spacesStore, "PATH:\"app:company_home\"");
$contentNode = $nodes[0];  

//create new file
$file_name = $_FILES['uploadedfile']['name'] . " (" . $timestamp . ")";
$file_tmp = $_FILES['uploadedfile']['tmp_name'];
$file_type = $_FILES['uploadedfile']['type'];
$file_size = $_FILES['uploadedfile']['size'];

$upload = $contentNode->createChild('cm_content', 'cm_contains', $file_name);
$contentData = new ContentData($upload, "cm:content");

$contentData->mimetype = $file_type;
$upload->cm_name = $file_name;
$upload->cm_description = 'Test File Description';
$contentData->size = $file_size;
$contentData->encoding = 'UTF-8';
$upload->cm_content = $contentData;

echo "Content set<br>";

try {
  echo "Saved changes to " . $upload->getId() . "<br>";
} catch (Exception $e) {
  echo 'Caught exception: ';