3

I'm trying to write a query to select media items which have no attachment. Is there some default value for empty images which can be used in a query? I'm trying to use

/sitecore/content/Tennant/Tennant/Company/Brand/Site/Media//*[@@templateid="{EB3FB96C-D56B-4AC9-97F8-F07B24BB9BF7}" and @Blob=""]

but this is returning no items, even though I can clearly see Media Items with no images under the above path.

2

If a media item has no attachment, and the attachment has been detached correctly using the Detach option on the Blob field then details about the media item will be wiped. You can check the the Size field is empty:

/sitecore/#media library#/Files//*[@size = '']

The above query will return all items from the Files folder in the media library. Your original query appears to be targeting content items, not the media library (assume this was just a incorrect example). The Template ID which you are targeting is also for Versioned JPEG, so also make sure your media items are of the above template type (I mention this since the default in Sitecore is to upload unversioned media).

  • Thanks for the answer. Its an SXA site and I believe that is a done thing in SXA to place media items in the content section beneath the site root. Strange thing I'm noticing now after seeing your tip about using the Size property is that many images are missing this, although the do have an image attached. – Matthew Dresser Jan 29 '18 at 2:44
  • Interesting, SXA must add additional providers + locations for media. You could also try the query with *[@blob = ''] if you want to directly check the blob field. – jammykam Jan 29 '18 at 5:13
  • Oh yes, I did try `[@blob = ''] first, didn't notice I had pasted that nonsense query in the question! – Matthew Dresser Jan 29 '18 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.