After getting an image as IPublishedContent, I try to get the Url or use the GetCropUrl method and they both return nothing.
I first get the a folder using Umbraco.TypedMedia, and then I get the Children of the folder(I filter them out to be only images). Some of the Children return an empty Url. If I try to get property value for the property "umbracoAlias", it also returns nothing, but if I use the method HasValue("umbracoAlias") it returns true.
This issue doesn't come up for all media items. I searched in the index to see the difference between an image that works and one that doesnt.
This one works:
This one doesnt:
Has anyone encountered this issue before or can anyone give me a hint or an idea as to why this could be happening?
I doubt that Media can be IPublishedContent. Maybe you need something like IMedia?https://our.umbraco.org/Documentation/Reference/Management/Models/Media
Investigating the real filename probably gives an indication of what goes wrong. If for example Stella-1.jpg actually refers to a file Stella-1.jpg.jpg, try to see if it works when you rename it.
I am pretty sure you can. I have done a lot of times and still do it. If you use Umbraco.TypedMedia you get media items as IPublishedContent.
@Micha
I think that when the Stella image was uploaded, the name was set by default as the fileName. Since nobody changed it it stayed like that, while the dialog image name was changed manually by someone. I don't think the name affects the url because the url will always be path to the file, while the name can be edited.
Sure, renaming may not solve it, but the original filename may explain what goes wrong.
Do you know the original filename for dialog-samtale-helsingoer.
Does it contain special symbols that Umbraco transformed to something different in the urlname?
The only time i have seen this happen is when the index is out of sync. Try rebuilding your internal and external index. If that does not work try re saving media item with broken link.
Also can you double check your umbraco log file see if there are any indexing errors in there?
Can you see the (problematic) media file in Umbraco (under Media)?
If no, could you check if it's in the Recycle Bin.
If it has been deleted, the file might still be available on the website but is (probably) not being indexed anymore.
The image is not deleted. I can see it in the Media section in Umbraco and if I look at the url saved in the index, I can find it on the server.
I forgot to mention that if I use the mediaService I can get the value of "umbracoFile". It is only if I try to get it from the IPublishedContent, the value is empty.
I am not sure if, after changing a media item, the updated media item will "automatically" be available in the mediaservice.
I would hope it is, but hopefully someone with more experience on that topic can tell more about it ...
However, since the mediaLink=null for the problematic image, I wonder:
Is this image published somewhere on a page?
If it is, is it possible to republish that page?
Dropping property "image" because it does not belong to the content
type.
it probably is about the same problem.
Unfortunately it does not really give a solid solution but several suggestions are given (and also a lot that did not help, so you do not have to try these ones anymore)
One of the interesting looking suggestions (not tried myself) is about pulling media from the database via the old api:
var media = new umbraco.cms.businesslogic.media.Media(mediaID);
if( media != null && media.ContentType.Alias != "Folder" )
{
return media.getProperty("umbracoFile").Value.ToString();
}
Ok, I figured out what is wrong. The umbracoFile property is supposed to store a json object with the values for the image cropper. The json object has a property called focal point which is supposed to contain two properties called top and left and they store percentage values (if left is 0.5 it means the focal point is in the middle of the image horizontally). The image that fails has a focal point with properties called left and right.
Thank you all for your answers and the time you put in to help me.
I don't think this is an issue coming from Umbraco. We used to have our own image cropper on images and I think this is old data left from the old image cropper.
Url is empty for Media
After getting an image as IPublishedContent, I try to get the Url or use the GetCropUrl method and they both return nothing.
I first get the a folder using Umbraco.TypedMedia, and then I get the Children of the folder(I filter them out to be only images). Some of the Children return an empty Url. If I try to get property value for the property "umbracoAlias", it also returns nothing, but if I use the method HasValue("umbracoAlias") it returns true.
This issue doesn't come up for all media items. I searched in the index to see the difference between an image that works and one that doesnt.
This one works:
This one doesnt:
Has anyone encountered this issue before or can anyone give me a hint or an idea as to why this could be happening?
Umbraco version 7.5.3 assembly: 1.0.6092.24019
I doubt that Media can be IPublishedContent. Maybe you need something like IMedia?https://our.umbraco.org/Documentation/Reference/Management/Models/Media
Although I don't know the reason why, it is remarkable that one node has a nodeName with an extension .jpg in it and the other doesn't.
nodeName: Stella-1.jpg <==> dialog samtale helsingoer (without .jpg)
Investigating the real filename probably gives an indication of what goes wrong. If for example Stella-1.jpg actually refers to a file Stella-1.jpg.jpg, try to see if it works when you rename it.
@Aleksey
I am pretty sure you can. I have done a lot of times and still do it. If you use Umbraco.TypedMedia you get media items as IPublishedContent.
@Micha I think that when the Stella image was uploaded, the name was set by default as the fileName. Since nobody changed it it stayed like that, while the dialog image name was changed manually by someone. I don't think the name affects the url because the url will always be path to the file, while the name can be edited.
Hi Carmen,
Sure, renaming may not solve it, but the original filename may explain what goes wrong. Do you know the original filename for dialog-samtale-helsingoer. Does it contain special symbols that Umbraco transformed to something different in the urlname?
Hi Micha,
I don't know the original filename.
Carmen,
The only time i have seen this happen is when the index is out of sync. Try rebuilding your internal and external index. If that does not work try re saving media item with broken link.
Also can you double check your umbraco log file see if there are any indexing errors in there?
Regards
Ismail
Hi Ismail
This is after reindexing. I can try to save the image and look more in the log files and see if there's anything I missed.
Looked in the logs and I cannot find indexing errors.
Hi Carmen,
Can you see the (problematic) media file in Umbraco (under Media)?
If no, could you check if it's in the Recycle Bin. If it has been deleted, the file might still be available on the website but is (probably) not being indexed anymore.
If yes, which file is it linked to?
Hi Micha,
The image is not deleted. I can see it in the Media section in Umbraco and if I look at the url saved in the index, I can find it on the server.
I forgot to mention that if I use the mediaService I can get the value of "umbracoFile". It is only if I try to get it from the IPublishedContent, the value is empty.
Hi Carmen,
Try to use MediaService - if it will return Url of image - than problem with cache or index.
MediaService works with database directly, so if it will return empty image - the problem with database.
Read more - https://our.umbraco.org/documentation/reference/management/services/mediaservice
Be aware - mediaService isn't recommended to use on the clientSide in Razor for example, so this experiment only for this case.
Thanks,
Alex
Hi Carmen,
I am not sure if, after changing a media item, the updated media item will "automatically" be available in the mediaservice. I would hope it is, but hopefully someone with more experience on that topic can tell more about it ...
However, since the mediaLink=null for the problematic image, I wonder:
Is this image published somewhere on a page? If it is, is it possible to republish that page?
Mmm ... just found the following post that looks related to this issue:
https://our.umbraco.org/forum/developers/razor/57936-TypedMedia-URL-is-empty
If your log contains the text:
it probably is about the same problem.
Unfortunately it does not really give a solid solution but several suggestions are given (and also a lot that did not help, so you do not have to try these ones anymore)
One of the interesting looking suggestions (not tried myself) is about pulling media from the database via the old api:
Hope this will help finding a solution ...
Ok, I figured out what is wrong. The umbracoFile property is supposed to store a json object with the values for the image cropper. The json object has a property called focal point which is supposed to contain two properties called top and left and they store percentage values (if left is 0.5 it means the focal point is in the middle of the image horizontally). The image that fails has a focal point with properties called left and right.
Thank you all for your answers and the time you put in to help me.
Good to see that you found the difference that explains why it caused problems!
Just out of curiousity, but do you also know why the properties for the focal point were named differently? Is it something in Umbraco that caused it?
I don't think this is an issue coming from Umbraco. We used to have our own image cropper on images and I think this is old data left from the old image cropper.
is working on a reply...