Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
MediaData implements IContentMedia. If you only want to get images, you can call with CommerceImage instead.
I have no idea why it "suddenly" happen to you
My bad. We had some problems and modified the ValidateCorrectType() and there for a PDF was considered a valid image.
Thanks again!
Hi!
We have used the Quicksilver extension for getting images for a product. All of a sudden it also returns pdf files.
Externsion method:
public static IList<string> GetAssets<TContentMedia>(this IAssetContainer assetContainer, IContentLoader contentLoader, UrlResolver urlResolver, string defaultAssets) where TContentMedia : IContentMedia { var assets = new List<string>(); if (assetContainer.CommerceMediaCollection != null) { assets.AddRange(assetContainer.CommerceMediaCollection.Where(x => ValidateCorrectType<TContentMedia>(x.AssetLink, contentLoader)).Select(media => urlResolver.GetUrl(media.AssetLink))); } if (!assets.Any()) { assets.Add(defaultAssets); } return assets; }
Up until now the above code gave me only images. Has this function been updated?
The PDF is GenericData
[ContentType(GUID = "6ab524b7-0c98-4b67-bb5f-66d8090accd0")] [MediaDescriptor(ExtensionString = "txt,pdf,docx,doc,xlsx,xls")] public class GenericMedia : MediaData { public virtual string Description { get; set; } }
And images are ImageMediaData:
[ContentType(GUID = "20644be7-3ca1-4f84-b893-ee021b73ce6c")] [MediaDescriptor(ExtensionString = "jpg,jpeg,jpe,ico,gif,bmp,png")] public class ImageMediaData : CommerceImage { }
/Kristoffer