cancel
Showing results for 
Search instead for 
Did you mean: 

Problem executing thumbnail example

kamlesh
Champ in-the-making
Champ in-the-making
Hi,

I am completely new to Alfresco JavaScript APIs and WebScripts. I have downloaded the thumbnail's example source code from Jeff's blog [http://ecmarchitect.com/archives/2009/03/03/913]. It uses two scripts one to upload a file and create thumbnail and other to fetch the thumbnail. Following are the scripts:

helloworldform.post.js

for each (field in formdata.fields) {
   if (field.name == "file" && field.isFile) {
      filename = field.filename;
      content = field.content;
      mimetype = field.mimetype;
   }
}
var results = search.luceneSearch("+PATH:\"app:company_home/cm:Someco/cm:Images\"");
var targetFolder = results[0];
var newDoc = targetFolder.createFile(filename); //line A
//var newDoc = companyhome.createFile(filename);//line B
newDoc.properties.content.write(content);
newDoc.properties.content.mimetype = mimetype;
newDoc.save();

// if we know we will always want a thumbnail for this object
// we could request that it be created here or we can do it later
newDoc.createThumbnail("scImageThumbnail", true);//line C

imagelist.get.js

var results = search.luceneSearch("+PATH:\"app:company_home/cm:Someco/cm:Images\"");
var targetFolder = results[0];
model.images = targetFolder.children;//line D
//model.images = companyhome.children;//line E

Now, the problem is when I run the above script target folder comes as null and hence the script results in an exception. When I comment line A and run the script with line B uncommented, it works and uploads the file in company home folder. So here is the problem with the lucene query and it is not returning me the values. But where has the cm:Images come from in the example I am unable to figure out. Also though the code at line C is not giving any exception neither it is generating any thumbnail as a child node of the document uploaded. What could be the reason?

Now with line B uncommented in first js, I commented line D in imagelist.js and uncommented line E. But this time the javascript is throwing an exception saying 'companyhome' is undefined. So i guess there is some problem with the scope of the companyhome variable. can you please tell me how can I modify the imagelist.js to make my code working.

Any help will be appreciated,
- Kamlesh
3 REPLIES 3

mikeh
Star Contributor
Star Contributor
I'm unfamiliar with the script, but it looks like you just need to create the Someco / Images folder hierarchy under Company Home.

Thanks,
Mike

kamlesh
Champ in-the-making
Champ in-the-making
Thanks Mike,

You are right! I have just changed the folder name to an appropriate value and my problem got sorted out. And regarding generation of thumbnails, in the example code the scImageThumbnail is defined to have mime type as image/png, so when I upload an image document, there thumbnail are generated. But same I want to achieve for the other mime types like text/plain or application/pdf. I have added the bean declaration for the same by using just copy paste of the existing bean declaration. But it is not working and the thumbnails are being generated for images only. The xml file is given below for reference:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
   <bean id="someco.thumbnailRegistry" class="com.someco.thumbnails.ThumbnailRegistryBootstrap" depends-on="ThumbnailService" init-method="init">
      <property name="thumbnailService" ref="ThumbnailService" />
      <property name="thumbnailDefinitions">
         <list>
            <bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
               <property name="name" value="scImageThumbnail" />
               <property name="mimetype" value="image/png"/>
               <property name="transformationOptions">
                  <bean class="org.alfresco.repo.content.transform.magick.ImageTransformationOptions">
                     <property name="resizeOptions">
                        <bean class="org.alfresco.repo.content.transform.magick.ImageResizeOptions">
                           <property name="height" value="100"/>
                           <property name="maintainAspectRatio" value="true"/>
                           <property name="resizeToThumbnail" value="true" />
                        </bean>
                     </property>
                  </bean>
               </property>
               <property name="placeHolderResourcePath" value="alfresco/extension/thumbnail/thumbnail_placeholder_scImageThumbnail.png" />
             </bean>
            <bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
               <property name="name" value="scTextThumbnail" />
               <property name="mimetype" value="text/plain"/>
               <property name="transformationOptions">
                  <bean class="org.alfresco.repo.content.transform.magick.ImageTransformationOptions">
                     <property name="resizeOptions">
                        <bean class="org.alfresco.repo.content.transform.magick.ImageResizeOptions">
                           <property name="height" value="100"/>
                           <property name="maintainAspectRatio" value="true"/>
                           <property name="resizeToThumbnail" value="true" />
                        </bean>
                     </property>
                  </bean>
               </property>
               <property name="placeHolderResourcePath" value="alfresco/extension/thumbnail/thumbnail_placeholder_scImageThumbnail.png" />
             </bean>
            <bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
               <property name="name" value="scPdfThumbnail" />
               <property name="mimetype" value="application/pdf"/>
               <property name="transformationOptions">
                  <bean class="org.alfresco.repo.content.transform.magick.ImageTransformationOptions">
                     <property name="resizeOptions">
                        <bean class="org.alfresco.repo.content.transform.magick.ImageResizeOptions">
                           <property name="height" value="100"/>
                           <property name="maintainAspectRatio" value="true"/>
                           <property name="resizeToThumbnail" value="true" />
                        </bean>
                     </property>
                  </bean>
               </property>
               <property name="placeHolderResourcePath" value="alfresco/extension/thumbnail/thumbnail_placeholder_scImageThumbnail.png" />
             </bean>
             <bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
               <property name="name" value="scTinyImageThumbnail" />
               <property name="mimetype" value="image/png"/>
               <property name="transformationOptions">
                  <bean class="org.alfresco.repo.content.transform.magick.ImageTransformationOptions">
                     <property name="resizeOptions">
                        <bean class="org.alfresco.repo.content.transform.magick.ImageResizeOptions">
                           <property name="width" value="35"/>
                           <property name="height" value="35"/>
                           <property name="maintainAspectRatio" value="false"/>
                           <property name="resizeToThumbnail" value="true" />
                        </bean>
                     </property>
                  </bean>
               </property>
               <property name="placeHolderResourcePath" value="alfresco/extension/thumbnail/thumbnail_placeholder_scTinyImageThumbnail.png" />
             </bean>
          </list>
       </property>
    </bean>
</beans>

Any suggestion?

- Kamlesh

mikeh
Star Contributor
Star Contributor
What happens when you call newDoc.createThumbnail(); with the other thumbnail types?

Mike