Translate

Saturday, November 16, 2013

Example 4: Rendering Blobs

This post illustrates how to render blobs (BINARY LARGE OBJECTS)

GENERAL STEPS TO FOLLOW:
  1. Load the flex asset (using assetset tags) 
  2. Get the value of imagefile attribute in list (using assetset:getattributevalues tag) 
  3. Retrieve information using blobservice tags 
CASE 1: If we are using normal upload functionality for images while creating asset and if you know asset type(c) and asset id (cid). This is used to render image asset as shown below:

<ics:if condition='<%=ics.GetVar("c")!=null && ics.GetVar("cid")!=null%>'><ics:then>
<!-- Use assetset tags to load FLEX ASSETS. CheckOut tagReference for further details. -->
<assetset:setasset name='Media' type='<%=ics.GetVar("c") %>' id='<%=ics.GetVar("cid")%>' />
<assetset:getattributevalues name='Media' immediateonly='true' typename='FlexAssetAttributeType' attribute='ImageFile' listvarname='mediaImageList' />
                 
<!-- 
BLOB attributes are to be rendered differently and uses BlobServer servlet.
Don't forget to include tld in your template/CSElement for BlobService -> taglib prefix="blobservice" uri="futuretense_cs/blobservice.tld"
 -->                  
<ics:if condition='<%=ics.GetList("mediaImageList")!=null && ics.GetList("mediaImageList").hasData()%>'>
<ics:then>        
      <ics:listloop listname='mediaImageList'>
<ics:listget listname='mediaImageList' fieldname='value' output='media_image' />
      
 <blobservice:gettablename varname="uTabname"/>
 <blobservice:getidcolumn varname="idColumn"/>
 <blobservice:geturlcolumn varname="uColumn"/>
 
 <render:getbloburl 
 blobtable='<%=ics.GetVar("uTabname")%>' 
 blobcol='<%=ics.GetVar("uColumn")%>'
 blobheader="image/jpeg"
 blobkey='<%=ics.GetVar("idColumn")%>'
 blobwhere='<%=ics.GetVar("media_image")%>' 
 outstr="imageURL"/> 
    </ics:listloop>
   
<img  src='<%=ics.GetVar("imageURL")%>' >
  
      </ics:then></ics:if>   
          
</ics:then></ics:if>

INFO:
  • Media is just a name used in Assetset tag
  • This code in template should be created once and called from various template/cselement as required by passing c and cid to render blobs.
  •  FlexAssetAttributeType is attribute type (For eg: It would be something like Media_A if you have created flex family using Media_* where *=CD, C, PD, P, A and F)
  • Always do a null check and use log messages to capture errors.

CASE 2: This case may be trickier. If you have stored your images under some folder say "image" in Shared directory, then you can obtain url value of blob, we can use blobservice.readdata as followed and render the image:

<ics:if condition='<%=ics.GetVar("c")!=null && ics.GetVar("cid")!=null%>'><ics:then>
<!-- Use assetset tags to load FLEX ASSETS. CheckOut tagReference for further details. -->
<assetset:setasset name='Media' type='<%=ics.GetVar("c") %>' id='<%=ics.GetVar("cid")%>' />
<assetset:getattributevalues name='Media' immediateonly='true' typename='FlexAssetAttributeType' attribute='ImageFile' listvarname='mediaList' />
<%if (ics.GetList("mediaList") != null && ics.GetList("mediaList").hasData()) { %>
<ics:listget listname='mediaList' fieldname='value' output='mediaFile' />
<%} %>
<%if (ics.GetVar("mediaFile") != null ) { %>
<blobservice:readdata id='<%=ics.GetVar("mediaFile") %>' listvarname="mediaInfo"/>
<%} %>
<% if (ics.GetList("mediaInfo") != null && ics.GetList("mediaInfo").hasData()) 
{
ics.SetVar("mediaURL", "/media/" + ics.GetList("mediaInfo").getValue("urldata").replace("\\", "/"));
}
%>

<img src='<%= ics.GetVar("mediaURL") %>' >

INFO:
  • Create one folder "media" in Shared directory and place all your images.
  • Add this property in server.xml if you are using apache tomcat which is located in conf directory:     <Context path="/media" docBase="<installed location of fatwire>/Shared/ccurl" reloadable="true" debug="1" crossContext="true"/>
----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------

No comments: