Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 23, 2011 @ 09:06
    Fuji Kusaka
    0

    FileSize when uploading pdf

    Can someone explains how to display the filesize of an uploaded document. I have an upload field where client can upload either a pdf or doc file, but now i want to display the filesize of the doc as well.

    Here is how am doing it in my xslt

     <xsl:template name="factsheet">
           <xsl:variable name="pdf" select="dwlfactsheets" />
          <xsl:variable name="fileSize" select="umbracoBytes"/>
                <xsl:if test="$pdf !=''"
                <li>            
                    <a target="_blank">
                     <xsl:attribute name="title">
                       <xsl:value-of select="@nodeName" />                 
                    </xsl:attribute>
                    
                    <xsl:attribute name="href">                    
                       <xsl:value-of select="dwlfactsheets"/>                                  
                      </xsl:attribute>Download Factsheet <xsl:value-of select="$fileSize"/>
             
                      <xsl:choose>
                        <xsl:when test="$fileSize &gt;= 1048576">
                          <xsl:value-of select="round($fileSize div 1048576)"/> MB              
                        </xsl:when>
                        <xsl:when test="$fileSize &gt;= 1024">
                          <xsl:value-of select="round($fileSize div 1024)"/> KB            
                        </xsl:when>
                        <xsl:when test="$fileSize &gt;0 and $fileSize &lt; 1024">
                          <xsl:value-of select="$fileSize"/>Bytes

                        </xsl:when>
                      <xsl:otherwise>
                           <xsl:text>0 Bytes</xsl:text>
                      </xsl:otherwise>
        </xsl:choose>     
                      
                </a> </li>
  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Nov 23, 2011 @ 09:38
    Darren Ferguson
    0

    Maybe wire up an ICustomFormatter like this one as an XSLT extension?

    http://flimflan.com/blog/FileSizeFormatProvider.aspx

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 23, 2011 @ 10:56
    Lee Kelleher
    1

    Hi Fuji,

    You know what I'm going to say already... uComponents to the rescue! Ta-dah!

    In the IO XsltExtension, there is a method called FormatFileSize ... pass the "umbracoBytes" property into that, it will return you a pretty filesize.

    <xsl:value-of select="ucomponents.io.FormatFileSize(umbracoBytes)" />

    Cheers, Lee.

  • Rodion Novoselov 694 posts 859 karma points
    Nov 23, 2011 @ 11:02
    Rodion Novoselov
    0

    Hi. I must have misunderstood but what's wrong with your code? For the first look it should work for any file stored in Media.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 23, 2011 @ 11:07
    Lee Kelleher
    0

    Fuji, I agree with Rodion - your original XSLT snippet looks right and would work (apart from you are displaying the "$fileSize" twice).

    I was offering an alternative option - absolutely nothing wrong with doing this in your XSLT.

    Cheers, Lee.

  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 24, 2011 @ 17:21
    Fuji Kusaka
    0

    Hi Lee, yes i added $fileSize just to see what was the value being output. Just for the record am not displaying docs from media section, am uploading the file from the Content Node itlself, but cant get the actual filesize.

Please Sign in or register to post replies

Write your reply to:

Draft