cancel
Showing results for 
Search instead for 
Did you mean: 

Content Conversion failed

nancyaggarwal
Champ in-the-making
Champ in-the-making
Hi all

I have to upload documents from web application into alfresco document library, for that i have written my code using openCMIS. My code is working perfectly, the documents are uploaded successfully in document library but when i lick on that document its preview is not working. It is <em>showing preview cannot be loaded from server </em>

can anyone help me with this issue?

Thanks
Nancy
9 REPLIES 9

rjohnson
Star Contributor
Star Contributor
This has happened to me.

Almost certainly your conversion is failing. You will find the error in alfresco.log. Very often this is a memory issue that will be temporarily cleared by a restart but you may need to allocate more memory / have more memory.

Bob Johnson

Thanks Bob for reply.

In my alfresco.log it is showing content conversion failed error caused by openoffice server conversion failed.
As you said in your post where i have to allocate more memory?

Nancy

Thanks Bob my problem is solved. But now i am truggling with the code which checks for the particular document which is already existed in document library or not? Can you please help me with the code.

Nancy

rjohnson
Star Contributor
Star Contributor
Nancy,

Don't know what CMIS wrapper you are using, but I have used the PHP one before now. Below is the code that checks to see if a document is in the document library of a given site and if is it it will call a function to update some of the metatdata (that function isn't in the snippet).

In this example, the file name I am looking for is the site short name with an extension of XML (e.g. if the site short name was an-employee, then I would be looking for an-employee.XML)


    function setMetaData($siteName, $empData, $getVar, $siteDescription, $sessionID, $empLocation) {
      $retVar = true;
        $ch = curl_init();
        $url = "localhost:8080/alfresco/service/farthest-gate/get-notice/site/";
        $url .= $siteName . "/documentLibrary?output=nodeonly&docname=" . $siteName . ".XML";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
      curl_setopt($ch, CURLOPT_USERPWD, $getVar);
        curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_TIMEOUT, '3');
        $response = curl_exec($ch);
      curl_close($ch);
      // Response SHOULD be a JSON response
      try {
         $or = json_decode($response);
         if(!@$or->items[0]->nodeRef) {
            echo "Site XML file not found\r\n";
            $retVar = false;
         } else {
            $jsonPost = $this->setJSON($empData, $empLocation);
              $ch = curl_init();
              $nodeRef = str_replace("://", "/", $or->items[0]->nodeRef);
            $url = "localhost:8080/share/proxy/alfresco/api/node/" . $nodeRef . "/formprocessor";
              curl_setopt($ch, CURLOPT_URL, $url);
              curl_setopt($ch, CURLOPT_HEADER, FALSE);
              $sessionCookie = sprintf("JSESSIONID=%s",$sessionID);
            curl_setopt($ch, CURLOPT_COOKIE, $sessionCookie);
            $headerOptions[0] =  "Content-Type: application/json";
            $headerOptions[1] =  "Accept: application/json";
            $headerOptions[2] =  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            $headerOptions[3] =  "X-Requested-With: application/x-www-form-urlencoded";
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headerOptions);
              curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonPost);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
              $response = curl_exec($ch);
            curl_close($ch);
            // Response SHOULD be a JSON response
            try {
               $or = json_decode($response);
               if($or == NULL) {
                  echo "Alfresco service returned invalid JSON $response\r\n";
                  $retVar = false;
               } else {         
                  if(@$or->message) {         
                     if(strpos($or->message,"Successfully persisted form") === FALSE) {
                        echo "Alfresco service returned error $or->message\r\n";
                        $retVar = false;
                     } else {
                        echo "Employee metadata for $siteName ($siteDescription) updated\r\n";
                     }
                  } else {
                     echo "Alfresco service did not update metadata responded with $response\r\n";
                     $retVar = false;
                  }
               }
            } catch (Exception $e) {
               echo "Request returned invalid JSON. response: ". $repsonse . " Exception: ". $e.getMessage() . "\r\n";
               $retVar = false;
            }   
         }
      } catch (Exception $e) {
         echo "Failed to update metadata ". $e.getMessage() . "\r\n";
         $retVar = false;
      }
      return $retVar;       
    }

Thanks BOB, my problem is solved.. But now i want the metadata should be displayed in my web application along with the documents. Can you help me with the code.

Thanks
Nancy

rjohnson
Star Contributor
Star Contributor
Nancy

Do you mean "How do I use CMIS to get the metatdata associated with a document?"

Bob

Yes Bob I mean this only. How can i use CMIS to get the metadata associated with a document.

Nancy

Nancy

Not sure how good your PHP is, but below is an edited script that I wrote that will retrieve the metadata associated with all documents of a given type and write it into a csv file.

Its basically an SQL query so you can adjust that to search on document name, noderef or anything else really.


<?php
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

require_once ('cmis_repository_wrapper.php');
$repo_url = $_SERVER["argv"][1];
$repo_username = $_SERVER["argv"][2];
$repo_password = $_SERVER["argv"][3];
@$repo_debug = $_SERVER["argv"][4];

$testfolios = array("xxxxx","yyyyyy");
$fname = "fred.csv";
$fhandle = fopen($fname,"w");

$client = new CMISService($repo_url, $repo_username, $repo_password);

$objs = $client->query("select cmis:objectId, cmis:objectTypeId, cmis:baseTypeId, cmis:name, cmis:creationDate, fgemp:mraempfolio, fgemp:mraempname, fgemp:mralocation, fgemp:mraapptdatetime, fgemp:mraapptwith, fgemp:mraattendedYN from fgemp:mgtrefappt");
foreach ($objs->objectList as $obj)
{
   if(!in_array($obj->properties['fgemp:mraempfolio'], $testfolios)) {
      @$apptdt = $obj->properties['fgemp:mraapptdatetime'];
      @$apptwh = $obj->properties['fgemp:mraapptwith'];
      $record = array($obj->properties['cmis:creationDate'],$obj->properties['fgemp:mraempfolio'],$obj->properties['fgemp:mraempname'],$obj->properties['fgemp:mralocation'],$apptdt,$apptwh,$obj->properties['fgemp:mraattendedYN']);
       fputcsv($fhandle, $record);
   }
}



Good luck

Bob

Thanks Bob this really helps me a lot.

Nancy