I'm developing a site and prior to deploying to dev and stage servers I am doing some dry runs on publishing and deploying the site. I've encountered an issue with umbracoFile, which works fin when ran in debug, via IIS8express but malfunctions once deployed to my IIS7 server.
I am using Umbraco7, VS 2013, SQL Server, IIS7 & IIS8express.
Simply put I am retrieving typed image data from a property like so :
var test = Umbraco.TypedMedia((int)award.GetPropertyValue("image")).GetPropertyValue("umbracoFile");
When I run the site (Release or Debug) and print out 'test' I get exactly what I expect, the path to the image (for example '/media/1001/image/png'). However Once Published and Deployed, while everything else is working swimmingly the same code churns out this :
{
"src": "/media/1001/image.png",
"crops": []
}
As you can see, this appears to be the right object, but serialised!
So my questions are; am I missing a reference or assembly in my package (I can imagine that an umbracoFile object is missing ergo the default output when echoed is not present, resulting in serialised object)?
Have I missed an include, which makes sense as this only happens on publish?
Perhaps I'm missing a config change in my web/umbraco config, seems unlikely as the path is relative and the root is set fine?
Am I missing some code or include, seems to work fine locally?
Can anyone help?
It may be a publishing issue, something not included/referenced however I have spent some time today reviewing my references and included files and can't find anything umbraco file/media related...
All my thanks in advance for any suggestings or advise!
Are you using the Image Cropper for the data type of that property by any chance? The only reason I ask is because your serialised data contains an empty collection.
If you are then I'd suggest using the GetGropUrl() method and adding some crops to your data type.
I am and I'm not! I followed the guide and set up Image Cropper, and is is indeed the Property Typenot the datatype! its Umbraco.MediaPicker(sorry I didn't mention the DataType). However I am not actually 'using' the type, as I don't require a crop in this case, I just based my property on it.
You do give me an idea though, I will re-check to see if Image Cropper is included in my deploy properly.
I'll also try the GetCropUrl method, I'll see if I can set up a 'no crop' crop, if you see what I mean (thse are logo's so can not be cropped, just resized hence imagegen). And I'll update on my success, however I worked this method first time before I moved focus from Image Crop to imagegen and the reason I ended up with the GetPropertyValue("umbracoFile") method was (I suspect) because it was the first method to give me the URL properly. Regardless I'm about to try that out!
It will be a completely suitable workaround, however I would like to get to the bottom of why the GetPropertyValue method works locally but not after publish. If anyone has any more thoughts or suggestions please let me know!
When I call GetCropUrl("image") I get a strange query string as so :
/?mode=pad&rnd=130549266000000000
So I'm guessing I need to look into this some more...
I may have mis-lead when I said I am using ImageCropper, it is installed but this field (alias "image") is a straight Umbraco.MediaPicker datatype, not umbraco.ImageCropper...
So I reason that this is why I'm not using GetCropUrl in this case.
THe origional problem is that while deveoping I uploaded my media before installing ImageCropper. This resulted in my origional code working and returning umbracoFile property. I got a clue from another post which I can't find that mentioned you need to 'touch' or resave an image for it to be saved as the ImageCropper type of image, and once I did this on my dev the return resembled my published version.
I can only assume that publishing somehow resaved these entries.
Following this I was able to forget about the simple string return and focus on handling the JObject being returned. Here's a summary of my solution.
@using Newtonsoft.Json.Linq
JObject test = Umbraco.TypedMedia((int)item.GetPropertyValue("image")).GetPropertyValue<JObject>("umbracoFile");
var output = "<img src=\"/imagegen.ashx?image=" + awardImage["src"] + "&height=140\" alt=\"ALT\" />";
Thanks for the advice, hope this helps someone somehow. Watch out iif you have Media added before installing ImageCropper!
Thank you all for giving some pointers.. Below is my discovery
Content of the umbracoFile is decided on what type of property editor is attached to that field. You can check that by navigating to the umbraco admin > Settings > Media Types > Image > umbracoFile
If the editor attached is ImageCropper, this field will hold Json string with the data. You delete this definition and add new umbracoFile attaching to Umbraco.UploadField editor then a string is saved..
umbracoFile not behaving on Publish/Deploy
Hi everyone,
I'm developing a site and prior to deploying to dev and stage servers I am doing some dry runs on publishing and deploying the site. I've encountered an issue with umbracoFile, which works fin when ran in debug, via IIS8express but malfunctions once deployed to my IIS7 server.
I am using Umbraco7, VS 2013, SQL Server, IIS7 & IIS8express.
Simply put I am retrieving typed image data from a property like so :
When I run the site (Release or Debug) and print out 'test' I get exactly what I expect, the path to the image (for example '/media/1001/image/png'). However Once Published and Deployed, while everything else is working swimmingly the same code churns out this :
As you can see, this appears to be the right object, but serialised!
So my questions are; am I missing a reference or assembly in my package (I can imagine that an umbracoFile object is missing ergo the default output when echoed is not present, resulting in serialised object)?
Have I missed an include, which makes sense as this only happens on publish?
Perhaps I'm missing a config change in my web/umbraco config, seems unlikely as the path is relative and the root is set fine?
Am I missing some code or include, seems to work fine locally?
Can anyone help?
It may be a publishing issue, something not included/referenced however I have spent some time today reviewing my references and included files and can't find anything umbraco file/media related...
All my thanks in advance for any suggestings or advise!
Danny "Blatant"
Hi Danny,
Are you using the Image Cropper for the data type of that property by any chance? The only reason I ask is because your serialised data contains an empty collection.
If you are then I'd suggest using the GetGropUrl() method and adding some crops to your data type.
Thanks, Dan.
Hi Dan,
I am and I'm not! I followed the guide and set up Image Cropper,
and is is indeed the Property Typenot the datatype! its Umbraco.MediaPicker(sorry I didn't mention the DataType). However I am not actually 'using' the type, as I don't require a crop in this case, I just based my property on it.You do give me an idea though, I will re-check to see if Image Cropper is included in my deploy properly.
I'll also try the GetCropUrl method, I'll see if I can set up a 'no crop' crop, if you see what I mean (thse are logo's so can not be cropped, just resized hence imagegen). And I'll update on my success, however I worked this method first time before I moved focus from Image Crop to imagegen and the reason I ended up with the GetPropertyValue("umbracoFile") method was (I suspect) because it was the first method to give me the URL properly. Regardless I'm about to try that out!
It will be a completely suitable workaround, however I would like to get to the bottom of why the GetPropertyValue method works locally but not after publish. If anyone has any more thoughts or suggestions please let me know!
Thanks,
Danny "Blatant"
As an update,
When I call GetCropUrl("image") I get a strange query string as so :
So I'm guessing I need to look into this some more...
I may have mis-lead when I said I am using ImageCropper, it is installed but this field (alias "image") is a straight Umbraco.MediaPicker datatype, not umbraco.ImageCropper...
So I reason that this is why I'm not using GetCropUrl in this case.
Any more thought?
Regards,
Danny "Blatant"
Another Ammendum,
Seems when I inspect the type of object returned by GetPropertyValue("image") I get 2 different things! On my localhost in debug I get
Whereas once deployed I get
I don't know what this 'means', but perhaps it leans to incorrect references again?
Regards,
Danny "Blatant"
I have resolved my issues eventually!
THe origional problem is that while deveoping I uploaded my media before installing ImageCropper. This resulted in my origional code working and returning umbracoFile property. I got a clue from another post which I can't find that mentioned you need to 'touch' or resave an image for it to be saved as the ImageCropper type of image, and once I did this on my dev the return resembled my published version.
I can only assume that publishing somehow resaved these entries.
Following this I was able to forget about the simple string return and focus on handling the JObject being returned. Here's a summary of my solution.
Thanks for the advice, hope this helps someone somehow. Watch out iif you have Media added before installing ImageCropper!
Cheers all,
Danny "Blatant"
Thank you all for giving some pointers.. Below is my discovery
Content of the umbracoFile is decided on what type of property editor is attached to that field. You can check that by navigating to the umbraco admin > Settings > Media Types > Image > umbracoFile
If the editor attached is ImageCropper, this field will hold Json string with the data. You delete this definition and add new umbracoFile attaching to Umbraco.UploadField editor then a string is saved..
is working on a reply...