Well in that case, some (or maybe just one) of your pages has no image picked - and since you're calling the GetMedia() function anyway, it errors out. Here's a way to cope with that:
<!-- Make sure an image was picked -->
<xsl:if test="normalize-space(previewImage)">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($currentPage/previewImage, 0)" />
<!-- Just to be safe from picked image having been deleted afterwards... -->
<xsl:if test="not($mediaNode[error])">
<img src="/ImageGen.ashx?image={$mediaNode/umbracoFile}&width=100&height=100" />
</xsl:if>
</xsl:if>
Thanks for the help. The logic behind no image & get media causing an error makes perfect sense.
Unfortunately, I dropped in the code you gave above, and I'm still getting the error: System.OverflowException: Value was either too large or too small for an Int32.
If I remove all the image code that we're toying with, the error goes away. I also tried using ($currentPage/...) and (./...) to no avail.
Yeah - that's because I'm a clown, posting wrong code :-)
You of course need to remove the $currentPage/ prefix inside the call to GetMedia() ...
<!-- Make sure an image was picked -->
<xsl:if test="normalize-space(previewImage)">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia(previewImage, 0)" />
<!-- Just to be safe from picked image having been deleted afterwards... -->
<xsl:if test="not($mediaNode[error])">
<img src="/ImageGen.ashx?image={$mediaNode/umbracoFile}&width=100&height=100" />
</xsl:if>
</xsl:if>
Okay - well then everything is working and we can go home :-)
Except it isn't, for some weird reason :-(
Well, let's see - which version of Umbraco are you using? The last one I posted should work for any version above 4.5.2 (assuming everything is spelled and cased correctly).
Only other reason I can see that code fail, would be if you have a previewImage property on any node below $currentPage with some bogus value in it (as in -31 or something greater than the limit of an Int32) ?
@Chriztian congrats on the achievement - keep'em coming sir! :)
In regard to the comment about MySQL this is as Chriztian says fully supported by Umbraco. However you should be aware that some packages for Umbraco are not neccesarily build with MySQL support in mind. But most of the time it's not an issue but it of course depends on the solution you're building etc.
Chriztian - sorry about that. Here's a sample of what I get:
Node: Motorola Citrus
Has previewImage: true
previewImage: 1241
previewImage XML?
1241
Also, I found if I don't use select="umbraco.library:GetMedia(./previewImage, 0)", and instead use select="umbraco.library:GetMedia($currentPage/previewImage, 0)", I don't get the error, but I don't get the image either.
The error is totally happening because somewhere among the nodes you're rendering, there's one with a serious attitude problem... and it doesn't make sense to me...
Could you try rendering, say, 10 images at a time? E.g. in the initial test before the image stuff:
<xsl:if test="normalize-space(previewImage) and position() < 10">
- and then increasing the number until the error appears?
It doesn't make sense to me at all - are you telling me that you're actually using the old Schema? 'Coz that doesn't make sense with the last one (changing from descendant:: to child).
And if you're not using the old schema, then you shouldn't even be getting image data in your Chrome debug output there...
I'm actually pretty baffled - but when everything works, please post the XSLT and I'll do the sane "So the reason *this* line didn't work..." etc., for everyone else that lands on this in the future :-)
Help displaying image from Media Picker with ImageGen
Hi there,
I'm trying to display and image from the Media Picker and ImageGen, but I can't seem to get it working properly. Here's what I've got:
<xsl:variable name="image" select="umbraco.library:GetMedia(./previewImage, 0)/umbracoFile" />
<xsl:if test="$image">
<img src="/ImageGen.ashx?image={$image}&width=100&height=100" />
</xsl:if>
I'm getting ever-so-helpful error:
System.OverflowException: Value was either too large or too small for an Int32.
Hi Damon,
Depending on where in the XSLT file you're doing this, you may need to tuck $currentPage onto the property, e.g.:
/Chriztian
Thanks for the suggestion. Unfortunately, I'm inside of an <xsl:for-each>, so I'm doing:
Am I going about this incorrectly?
Yeah, ok - makes sense.
Well in that case, some (or maybe just one) of your pages has no image picked - and since you're calling the GetMedia() function anyway, it errors out. Here's a way to cope with that:
/Chriztian
Chriztian -
Thanks for the help. The logic behind no image & get media causing an error makes perfect sense.
Unfortunately, I dropped in the code you gave above, and I'm still getting the error: System.OverflowException: Value was either too large or too small for an Int32.
If I remove all the image code that we're toying with, the error goes away. I also tried using ($currentPage/...) and (./...) to no avail.
Yeah - that's because I'm a clown, posting wrong code :-)
You of course need to remove the $currentPage/ prefix inside the call to GetMedia() ...
/Chriztian
Aha - so are you using an Media Picker or an Upload datatype for the previewImage property?
/Chriztian
Media Picker. Sorry - I should have made it more clear than I did in my original post.
Okay - well then everything is working and we can go home :-)
Except it isn't, for some weird reason :-(
Well, let's see - which version of Umbraco are you using? The last one I posted should work for any version above 4.5.2 (assuming everything is spelled and cased correctly).
Only other reason I can see that code fail, would be if you have a previewImage property on any node below $currentPage with some bogus value in it (as in -31 or something greater than the limit of an Int32) ?
/Chriztian
Ha! :) Using Umbraco v 4.9.0, Assembly version 1.0.4633.18696, on IIS 7, running on MySQL (yeek).
I'm just trying to select a normal PNG image. Also, the "$currentPage" never has a child node under it.
Okay - this will be my 1600th post here, so bear with me if I go all Academy Awards ... :-)
(YAY!)
I honestly can't think of a reason why this doesn't work...
Maybe you could try this instead of all the image code in the loop, and see if you can get any meaningful info about where it goes wrong?:
/Chriztian
@Chriztian congrats on the achievement - keep'em coming sir! :)
In regard to the comment about MySQL this is as Chriztian says fully supported by Umbraco. However you should be aware that some packages for Umbraco are not neccesarily build with MySQL support in mind. But most of the time it's not an issue but it of course depends on the solution you're building etc.
Just my 2 cents.
/Jan
Congrats on 1600! :)
I implemented your code - nice trick by the way! That will definitely be useful at some point I'm sure. BUT - all of code returned is good.
Even if I don't reference the image with imagegen, and instead use:
I STILL get the System.OverflowException: Value was either too large or too small for an Int32. error message...
When you say "all [...] code returned is good", what do you mean by that?
Did you get XML in the previewImage XML? fields?
Did you get any negative values for previewImage ID?
Any unusually large values?
(Just checking)
/Chriztian
Chriztian - sorry about that. Here's a sample of what I get:
previewImage
: truepreviewImage
: 1241previewImage XML?
1241
Also, I found if I don't use select="umbraco.library:GetMedia(./previewImage, 0)", and instead use select="umbraco.library:GetMedia($currentPage/previewImage, 0)", I don't get the error, but I don't get the image either.
This is indeed very strange Damon...
The error is totally happening because somewhere among the nodes you're rendering, there's one with a serious attitude problem... and it doesn't make sense to me...
Could you try rendering, say, 10 images at a time? E.g. in the initial test before the image stuff:
- and then increasing the number until the error appears?
/Chriztian
Chriztian -
Not totally sure what I should be doing with that last snippet.
I found this code snippet (I know this is old schema, but I'm grasping at straws, and it DOESN'T produce an error):
I fired up Chrome inspector tools, and I'm getting the following error:
http://.../media/13543/lion%20avatar.jpeg80804294jpeg 404 (Not Found)
FINALLY! In a desperate attempt, I changed my initial line from:
select="$currentPage/descendant::*[@isDoc]">
to:
select="$currentPage/* [@isDoc]">
and it started working. I can't believe I missed this.
Hi Damon,
It doesn't make sense to me at all - are you telling me that you're actually using the old Schema? 'Coz that doesn't make sense with the last one (changing from descendant:: to child).
And if you're not using the old schema, then you shouldn't even be getting image data in your Chrome debug output there...
I'm actually pretty baffled - but when everything works, please post the XSLT and I'll do the sane "So the reason *this* line didn't work..." etc., for everyone else that lands on this in the future :-)
/Chriztian
This is my code that seems to be doing what I want:
is working on a reply...