As the title suggests, I am attempting to pull some media via the function ( var mediaItem = Library.MediaById(imageID); ). I noticed that there is a gimmick which (after searching around) I cannot seem to find any problems that match mine. As such I am asking for help on either a solid workaround or help in catching the nasty little big.
Background Information:
Essentially, I am creating a front-end cropper (all of the work is finished, the error just started popping up after I was finishing up some jquery work on the front-side). I start off by running my front-end razor script which takes in the node-to-be-cropped via the URL. From there, it uses the Library.MediaById function to SUCCESSFULLY pull the media item and displays it on screen. From there I hook up jquery and send the stuff over to the backend.
From here I perform a million checks on the input parameters, and then attempt to pull the media item a second time via the above method. It is here that the error arrises, in that Library.MediaById(imageID) is returning the following the object: "umbraco.MacroEngines.DynamicNull". What confuses me is that the exact same function, with the exact same input parameters, is not giving the same output.
My current theory is that Library.MediaByID locks the file so that it can't be read//written to until something happens. Ultimately I have no clue why this is happening, and would appreciate any/all help on why this is happening.
Relevant code snippets:
Front End:
var mediaItem =Library.MediaById(imageID);//THIS WORKS mediaURL = mediaItem.url.ToString();//SO DOES THIS
var media =new umbraco.cms.businesslogic.media.Media(imageID);//workaround because width = media.getProperty("umbracoWidth").Value.ToString();//getting width/height using height = media.getProperty("umbracoHeight").Value.ToString();//library method was returning null as well
Back End:
var mediaItem =Library.MediaById(imageID);
var img = mediaItem.crops.Find("@name", cropStyle);//this gets me the CROP string imageURL = img.url.ToString(); string baseImage = mediaItem.url.ToString();//this gets me the BASE IMAGE
if(string.IsNullOrWhiteSpace(imageURL)){ json =Json.Encode("The image does not have the specified crop already created!"+ imageID + cropStyle + baseImage + mediaItem.GetType());//debug information. GetType returning umbraco.MacroEngines.DynamicNull Response.ContentType="application/json"; Response.Write(json); return; }
I tried to create a new media item to check to see if it is the examineindex that isn't updating properly. I checked to make sure that I could create the node, and it worked fawlessly!
Previously I thought that this wasn't a problem, because I downloaded the umbracco plugin for the examine viewer and manually reconstructed all of the tables (ontop of deleting temp//restarting my local host).
As such, my problem has no transformed into: How do I fix examine index to behave properly?
Well, using the above example I believe yes. By creating a brand new media item and linking it to that, it works. Saving old media items or republishing the nodes or even uploading new items into those nodes does not work. Only creating a brand new media item appears to work.
In all honesty this is really strange, because it works on one page but not another; which is really screwing with my standard troubleshooting methods.
edit:
Another thing that is throwing me off is reconstructing every index in the site, replubshing the site, or even just deleting my temp file in umbraco do not help in the least.
I'm not totally clear what is going on here, but I would suggest that you try using uQuery instead of DynamicNode. Instead of Library.MediaById use uQuery.GetMedia(imageID). There are then specifc methods for getting crops etc and this takes Examine out of the picture as uQuery does not use it.
I went ahead and tried your suggestion, but get the exact same problem. Here is my relevant code:
var mediaItemQ = uQuery.GetMedia(imageID);
try{
var something = mediaItemQ.GetType();
} catch(Exception ex){
json = Json.Encode(ex.Message + imageID);
Response.ContentType = "application/json";
Response.Write(json);
return; }
Where the try/catch fails while trying to edit an old node (in this case, 1367) with the message: "Object not set to an instance of an object.1367"
Now, when I plugin the exact same code to my new node (1473), the try/catch passes and the crop is created successfully (using the old code, mind you). I went ahead and inherited the umbraco libraries (" @using umbraco; ") which is where uQuery is located.
Noting this, that means that it cannot be an examine index problem, correct? Aside from file locking (which I don't think Umbraco does....) I cannot fathom what the problem is.
I'm afraid not. The only solution I found was to work around it.
But, as stated above, the code was just finicky. Really the only way to explain it. It worked in some areas, and in others it just blew up (giving the error above).
Looking at my code, we ended up replacing the dynamic content with:
Library.MediaByID(imageID) returning null conditionally
As the title suggests, I am attempting to pull some media via the function ( var mediaItem = Library.MediaById(imageID); ). I noticed that there is a gimmick which (after searching around) I cannot seem to find any problems that match mine. As such I am asking for help on either a solid workaround or help in catching the nasty little big.
Background Information:
Essentially, I am creating a front-end cropper (all of the work is finished, the error just started popping up after I was finishing up some jquery work on the front-side). I start off by running my front-end razor script which takes in the node-to-be-cropped via the URL. From there, it uses the Library.MediaById function to SUCCESSFULLY pull the media item and displays it on screen. From there I hook up jquery and send the stuff over to the backend.
From here I perform a million checks on the input parameters, and then attempt to pull the media item a second time via the above method. It is here that the error arrises, in that Library.MediaById(imageID) is returning the following the object: "umbraco.MacroEngines.DynamicNull". What confuses me is that the exact same function, with the exact same input parameters, is not giving the same output.
My current theory is that Library.MediaByID locks the file so that it can't be read//written to until something happens. Ultimately I have no clue why this is happening, and would appreciate any/all help on why this is happening.
Relevant code snippets:
Front End:
Back End:
Update:
I tried to create a new media item to check to see if it is the examineindex that isn't updating properly. I checked to make sure that I could create the node, and it worked fawlessly!
Previously I thought that this wasn't a problem, because I downloaded the umbracco plugin for the examine viewer and manually reconstructed all of the tables (ontop of deleting temp//restarting my local host).
As such, my problem has no transformed into: How do I fix examine index to behave properly?
bump. Need help on this please :)
Hi Nathan,
Just want to clarify are you now certain that it is Examine causing your issue?
Thanks,
Jeavon
Well, using the above example I believe yes. By creating a brand new media item and linking it to that, it works. Saving old media items or republishing the nodes or even uploading new items into those nodes does not work. Only creating a brand new media item appears to work.
In all honesty this is really strange, because it works on one page but not another; which is really screwing with my standard troubleshooting methods.
edit:
Another thing that is throwing me off is reconstructing every index in the site, replubshing the site, or even just deleting my temp file in umbraco do not help in the least.
I'm not totally clear what is going on here, but I would suggest that you try using uQuery instead of DynamicNode. Instead of Library.MediaById use uQuery.GetMedia(imageID). There are then specifc methods for getting crops etc and this takes Examine out of the picture as uQuery does not use it.
Full uQuery media documentation can be found here
Worth a try?
Interesting.
I went ahead and tried your suggestion, but get the exact same problem. Here is my relevant code:
var mediaItemQ = uQuery.GetMedia(imageID);
try{
var something = mediaItemQ.GetType();
} catch(Exception ex){
json = Json.Encode(ex.Message + imageID);
Response.ContentType = "application/json";
Response.Write(json);
return; }
Where the try/catch fails while trying to edit an old node (in this case, 1367) with the message: "Object not set to an instance of an object.1367"
Now, when I plugin the exact same code to my new node (1473), the try/catch passes and the crop is created successfully (using the old code, mind you). I went ahead and inherited the umbraco libraries (" @using umbraco; ") which is where uQuery is located.
Noting this, that means that it cannot be an examine index problem, correct? Aside from file locking (which I don't think Umbraco does....) I cannot fathom what the problem is.
any chance this was solved? I'm getting exactly the same issue
I'm afraid not. The only solution I found was to work around it.
But, as stated above, the code was just finicky. Really the only way to explain it. It worked in some areas, and in others it just blew up (giving the error above).
Looking at my code, we ended up replacing the dynamic content with:
//var mediaItem = Library.MediaById(imageID);
Media mediaItem = uQuery.GetMedia(imageID);
mediaURL = mediaItem.GetImageUrl();
I'm afraid that's all I've got.
Hi Nathan,
Thought I'd just chime in here for a dime ;-)
When calling:
You're getting a
dynamic
type which let your access it's properties by simply doing this:Since
umbracoFile
is the propertyalias for the image URL, this should output the image url.All the best,
Bo
Edit: after reading the original post, I'm not sure if this is the problem at all? ;-)
What it turned out to be for me was I needed to delete my media examine indexes and post a power out they were corrupt
is working on a reply...