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
    Jul 20, 2011 @ 05:44
    Fuji Kusaka
    0

    Best way of displaying umbracoBytes for a pdf file

    What is the best possible way of displaying file size of uploaded pdf using umbracoBytes?

     

    //fuji

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 20, 2011 @ 13:09
    Jan Skovgaard
    0

    Hi Fuji

    Could you ellaborate a bit more on your thoughts on this? Is it in visual terms on the frontend of a website or in the backend of Umbraco or?

    /Jan

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 20, 2011 @ 13:18
    Fuji Kusaka
    0

    Hey Jan,

    Its more on the frontend of the website. I would like to display the file size of uploaded pdf file that user will be able to download.

     

    //fuji

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 20, 2011 @ 14:27
    Kim Andersen
    0

    Hi Fuji

    Just like the umbracoFile, umbracoHeight etc. you can print out the umbracoBytes peoperty in the frontend using the GetMedia-extension. Is this what you want to do?

    /Kim A

  • Richard 146 posts 168 karma points
    Jul 20, 2011 @ 14:57
    Richard
    0

    I have used the following to display 15 KB or 3 MB:

        <xsl:call-template name="FileInfo">
    <xsl:with-param name="size" select="umbracoBytes"/>
    </xsl:call-template>
    ...

    <xsl:template name="FileInfo">
    <xsl:param name="size"/>

    <xsl:variable name="fileSize" select="round($size div 1000)"/>
    <xsl:choose>
    <xsl:when test="$fileSize &gt; 1000">
    <xsl:value-of select="round($fileSize div 1000)"/> MB
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$fileSize"/> KB
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jul 20, 2011 @ 15:01
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 21, 2011 @ 08:34
    Fuji Kusaka
    0

    Hi Kim,

    I tried this earlier but instead I get an parsing error

    <xsl:value-of select="umbraco.library:GetMedia($pdfFile, 'false')/umbracoBytes"/>

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 21, 2011 @ 12:06
    Kim Andersen
    0

    Hmm...could you try shoing us your whole xslt?

    The $pdfFile needs to contain a media node id. So you probably need to wrap the value-of inside an if-statement checking whether the $pdfFile is empty or not.

    /Kim A

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 21, 2011 @ 12:10
    Fuji Kusaka
    0

    Hi Kim,

     

    Here is how am doing it 

    <xsl:variable name="pdfFile" select="newsPDF" />
    <xsl:if test="$pdfFile != ''">
                  <a target="_blank">             
                    
                    <xsl:attribute name="class">
                      <xsl:text>pdf</xsl:text>
                    </xsl:attribute>                
                    
                    <xsl:attribute name="href">                    
                       <xsl:value-of select="newsPDF"/>                                  
                    </xsl:attribute>Download the pdf file                 
                </a>
              </xsl:if>  

     

    Its giving  me the right pdf file but would also like to show the file size

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 21, 2011 @ 13:44
    Kim Andersen
    0

    This newsPDF-field - is this an upload data type? It sure looks like that, when you're not using the GetMedia extension. Unless you've created your own XML, and put the path to the pdf in an element called newsPDF.

    /Kim A

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 21, 2011 @ 13:52
    Fuji Kusaka
    0

    Yes its an upload field where the client will decide if he wants to include a pdf file or not.

     

    //fuji

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 21, 2011 @ 14:04
    Lee Kelleher
    1

    Any know if an XsltExtension is already out there for getting the filesize from a filepath?

    If not, then I'll add one to uComponents (in the IO extension), for the next release! :-D

    Cheers, Lee.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jul 22, 2011 @ 12:01
    Bo Damgaard Mortensen
    0

    Hi Fuji,

    Out of couriosity, what does this give you: <xsl:copy-of select="$pdfFile" /> ? :-)

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 22, 2011 @ 12:23
    Kim Andersen
    0

    Lee, I haven't seen an extension like that anywhere, so go for it! It would be very useful in situations like this one. Maybe an extension to grab the width and height from a path would also be great in situations where it's an image that's uploaded. +1!

    /Kim A

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 22, 2011 @ 12:29
    Lee Kelleher
    0

    Hey Kim,

    Just added the "GetFileSize" extension to uComponents (here).  We've already got extensions for "GetImageHeight" and "GetImageWidth" - check out the docs. There's also one for getting the <img> tag itself: "GetImageHtml".

    Cheers, Lee.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 22, 2011 @ 14:26
    Kim Andersen
    0

    Ooh didn't see them Lee. My bad. But great work on the GetFileSize-extension! :)

    Will check it out soon.

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft