AnsweredAssumed Answered

WebScript to retrieve images from Alfresco

Question asked by ramos69 on Apr 13, 2010
Latest reply on Apr 13, 2010 by ramos69
Hello.. I'm new at Alfresco and i'm building a flex aplication to retrieve content from Alfresco.

I tried to adapt this webscript to my alfresco but i'm getting the ERROR Bellow…

Can Someone help me?

This is my webscript…


images.get.desc

<webscript>
    <shortname>Images API</shortname>
    <description>Images API</description>
    <url>/teste/{getImages}</url>
    <format default="xml">argument</format>
    <authentication>user</authentication>
    <transaction>required</transaction>
   <cache>
      <never>true</never>
   </cache>
</webscript>




images.get


// globals
var REPO_ROOT = "Company Home/ClientContent";
var IMAGES_FOLDER_NAME = "Images";


//
// Returns a list of images
function listImages() {
   logger.log( "listImages()" );

   var photosFolder = getRepoRoot(IMAGES_FOLDER_NAME);
   var searchResult = photosFolder.children;
   var photos = new Array();
   for( var i=0; i<searchResult.length; i++ ) {
      logger.log( "listImages() searchResult[i]=" + searchResult[i].name + ", mimetype=" + searchResult[i].mimetype );
      if( searchResult[i].mimetype == "image/gif"
        || searchResult[i].mimetype == "image/jpeg"
        || searchResult[i].mimetype == "image/png" ) {
         photos.push( searchResult[i] );
      }
   }

   return photos;
}

//
// return the node that points to the data repository folder in which to store nodes.
// optional path  parameter will be treated as a directory path relative to the
// root and the node pointed to by the path will be returned rather than the root itself.
// if the path does not exist it will be created.
//
function getRepoRoot( path ) {
   if( null == path ) {
      path = "";
   }

   var rootNodePath = REPO_ROOT + "/" + path;
   rootNodePath = rootNodePath.replace( "\\\\/+", "/" );
   logger.log( "getRepoRoot() look for path: " + rootNodePath );

   var paths = rootNodePath.split( "/" );
   logger.log( "getRepoRoot() paths.length=" + paths.length );
   if( paths.length>0 && ""==paths[0] ) {
      paths.shift();
   }
   var node = companyhome;
   for( var i=0; i< paths.length; i++ ) {
      if( 0==i && "Company Home" == paths[i] ) { continue; }
      if( !paths[i] ) { continue; }
      logger.log( "getRepoRoot() paths[i]=" + paths[i] );
      var childNode = node.childByNamePath( paths[i] );
      logger.log( "getRepoRoot() childNode=" + childNode.name );
      /*if( !childNode ) {
         childNode = node.createFolder( paths[i] );
         logger.log( "getRepoRoot() createFolder childNode=" + childNode.name );
      }*/
      node = childNode;
   }
   
   return node;
}

////////////////////

try {
   if( "getImages" == url.extension ) {
      model.resultset = listImages();
   } else {
      throw( "method " + url.extension + " not implemented" );
   }
} catch( apiError ) {
   logger.log( "ERROR processing API call " + url.full + " Error message: " + apiError );
   status.message = "ERROR processing API call " + url.full + " Error message: " + apiError;
   status.code = 400;
   status.redirect = true;
}

images.get.xml


<?xml version="1.0" encoding="UTF-8"?>

<images>
   <#list resultset as node>
      <image>
         <fileName>${node.name}</fileName>
         <filePath>http://10.0.20.5:8080/alfresco/alf_data/contentstore/2010/4/12/11/30/${node.id}/${node.name}</filePath>
      </image>
   </#list>
</images>


And this is the error that returns



…alfresco/service/teste/{getImages}

<response>

<status>
400
<name>Bad Request</name>

<description>
Request sent by the client was syntactically incorrect.
</description>
</status>

<message>
ERROR processing API call /alfresco/service/teste/{getImages} Error message: method {getImages} not implemented
</message>
<exception/>
<callstack>
  </callstack>
<server>Alfresco Community v3.2.0 (r 2384) schema 3.003</server>
<time>13/Abr/2010 12:12:47</time>
</response>

I suspect is the path  <filePath>http://10.0.20.5:8080/alfresco/alf_data/contentstore/2010/4/12/11/30/${node.id}/${node.name}</filePath> but I'v got 3 bin that i think its my nodeid and in the 11/ directory i've got more folders whith my other images….

Thanks from advance…..

Outcomes