Copied to clipboard

Flag this post as spam?

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


  • Nikolas van Etten 202 posts 162 karma points
    Feb 22, 2011 @ 01:24
    Nikolas van Etten
    0

    Any method for getting media node with correct content-type?

    I'm in need of retrieving on the fly an image from the media section and all that I have is the id of the media. Are there any methods or other ways which would give me the image when using only the id. Could be:

    http://www.mysite.com/imageparser.aspx?id=1234

    This should (if the id actually corresponds to an image) output a image with the correct content-type.

    I assume this should not be very complicated to create, but if it exists, I would prefer not to... ;)

  • Rich Green 2246 posts 4008 karma points
    Feb 22, 2011 @ 02:06
    Rich Green
    0

    hi,

    Yes, you can retrieve the image using a macro / xslt

    Something like (not tested)

    <xsl:template match="/">
        <xsl:variable name="mediaId" select="number(umbraco.library:Request('id'))" />
        <xsl:if test="$mediaId > 0">
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
            <xsl:if test="$mediaNode/umbracoFile">
                <img src="{$mediaNode/umbracoFile}" height="{umbracoHeight}" width="{umbracoWidth}" />
            </xsl:if>
        </xsl:if>
    </xsl:template>
    

    Rich

  • Rich Green 2246 posts 4008 karma points
    Feb 22, 2011 @ 02:08
    Rich Green
    0

    The above assumes it's an image, not sure if if thats what you're asking?it's late here... hope it helps in someway.

    Rich

  • Nikolas van Etten 202 posts 162 karma points
    Feb 22, 2011 @ 09:16
    Nikolas van Etten
    0

    Hi Rich,

    Thanks for your reply, but I'm afraid it's a bit more complicated. As i wrote, I need the image on the fly - basically after getting the id through an ajax call. So I'm not able to run any xslt or similar. Thus I need a way to get the image in such a way that I can output it like this:

    <img src="http://www.mysite.com/imageparser.aspx?id=1234" alt=""/>

    I'm considering doing a second ajax call just to get the image url string back in the ordinary way (using xslt), but I prefer not as it means yet another server call for what is really just a detail on the page.

     

    Nik

  • Rich Green 2246 posts 4008 karma points
    Feb 22, 2011 @ 09:31
Please Sign in or register to post replies

Write your reply to:

Draft