IC5Notice: We have upgraded developerWorks Community to the latest version of IBM Connections. For more information, read our upgrade FAQ.
Topic
  • 3 replies
  • Latest Post - ‏2013-01-30T20:37:00Z by SystemAdmin
SystemAdmin
SystemAdmin
6772 Posts

Pinned topic Get size of a file?

‏2013-01-29T01:20:05Z |
Is there a way to get the size of a file stored on DataPower from within an XSL stylesheet?

Thanks.
Updated on 2013-01-30T20:37:00Z at 2013-01-30T20:37:00Z by SystemAdmin
  • swlinn
    swlinn
    1346 Posts

    Re: Get size of a file?

    ‏2013-01-29T01:58:31Z  
    Perhaps an internal soma call for dp:get-filestore.

    Regards,
    Steve
  • HermannSW
    HermannSW
    4524 Posts

    Re: Get size of a file?

    ‏2013-01-29T09:27:08Z  
    • swlinn
    • ‏2013-01-29T01:58:31Z
    Perhaps an internal soma call for dp:get-filestore.

    Regards,
    Steve
    > Perhaps an internal soma call for dp:get-filestore.
    >
    It's much easier than that if only reading of file is needed -- just use <dp:url-open target="..." response="binaryNode"/> !

    For background information on dealing with Non-XML data in stylesheets please see/hear into these two WSTE webcasts:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    Here are two simple samples (accessing a file under "store:" or on the internet -- with proof for correct file size):
    
    $ echo 
    "<f>store:///identity.xsl</f>" | coproc2 fsize.xsl - http:
    //dp3-l3:2223 790 $ echo 
    "<f>http://stamm-wilbrandt.de/images/anim.gif</f>" | coproc2 fsize.xsl - http:
    //dp3-l3:2223 1782 $ wget -O - http:
    //stamm-wilbrandt.de/images/anim.gif -q | wc --bytes 1782 $ $ cat fsize.xsl <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:func=
    "http://exslt.org/functions" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <xsl:output omit-xml-declaration=
    "yes" /> <xsl:template match=
    "/"> <xsl:variable name=
    "resp"> <dp:url-open target=
    "{.}" response=
    "binaryNode"/> </xsl:variable>   <xsl:variable name=
    "b64file" select=
    "dp:binary-encode($resp/result/binary/node())" />   <xsl:value-of select=
    "func:base64-length($b64file)"/> <xsl:text>
    </xsl:text> </xsl:template> <!-- 
    
    return length of decoded base64 string $bytes (string-length replacement) --> <func:function name=
    "func:base64-length"> <xsl:param name=
    "bytes"/>   <xsl:choose> <xsl:when test=
    "contains($bytes,'==')"> <func:result select=
    "(string-length($bytes) div 4) * 3 - 2"/> </xsl:when> <xsl:when test=
    "contains($bytes,'=')"> <func:result select=
    "(string-length($bytes) div 4) * 3 - 1"/> </xsl:when> <xsl:otherwise> <func:result select=
    "(string-length($bytes) div 4) * 3"/> </xsl:otherwise> </xsl:choose> </func:function>   </xsl:stylesheet> $
    


     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Get size of a file?

    ‏2013-01-30T20:37:00Z  
    Thanks for the replies. Both methods seem expensive to just get a file size (I don't need to read the file). I'll mark this as answered, though, because these appear to be the only options.

    Thanks.