I'm new here

Is it possible to get the medias by type (such as PDF, doc, png)?

Dear All,

I would like to retrive the media using their file type,

The following code sinippets returns the Media by their UID


                        IDProvider.UidType.MEDIASTORE_LEAF, false);


Instead of retriving the media only with UID, i need to check the file type also. if the UID and file type are matched then media should return.

is this possible with the FS Access API?

Thank you!

Labels (1)
Tags (2)
3 Replies
Returning Responder

Re: Is it possible to get the medias by type (such as PDF, doc, png)?

Hello Kavin,

as far as I know this is not possible with the standard FirstSpirit Access-API. The file extension of a media element (File or Picture) is deeply inside the object structure.

For a File you can get is with:

String extension = media.getFile(language).getExtension();

See: http://www.e-spirit.com/odfs51/access/de/espirit/firstspirit/access/store/mediastore/Media.html#getF... and http://www.e-spirit.com/odfs51/access/de/espirit/firstspirit/access/store/mediastore/File.html#getEx...

And for a picture with:

String extension = media.getPicture(language).getPictureResolution(resolution).getExtension();

See: http://www.e-spirit.com/odfs51/access/de/espirit/firstspirit/access/store/mediastore/Media.html#getP..., http://www.e-spirit.com/odfs51/access/de/espirit/firstspirit/access/store/mediastore/Picture.html#ge... and http://www.e-spirit.com/odfs51/access/de/espirit/firstspirit/access/store/mediastore/PictureResoluti...

So I think you have to implement the logic by yourself. You have to get all media objects from the store, iterate over the Listable of media objects, check if they are files or pictures, retrieve the file extension and if the file extension matches the one you want put the media object into a map or list or something else.

Be sure that you iterate only once over the list of all media objects because of performance reasons. So create the list of UID's and file extensions you want to match first and then check each media objects if it matches one of the combinations. Do not check all media objects for combination A and then again all media objects for combination B and so one.

Or just get the one media by UID you want to have and then check the file extension of this one media object!

I hope that this answer will help you.



0 Kudos
Crownpeak employee
Crownpeak employee

Re: Is it possible to get the medias by type (such as PDF, doc, png)?

Hi Kavin,

a full store iteration should only be used if there is no other way. Fortunately, at least for the current store you can use a QueryAgent and "fs.extension=EXTENSION". You can create a combined query like

QueryAgent queryAgent = context.requireSpecialist(QueryAgent.TYPE);

Iterable<IDProvider> result = queryAgent.answer("fs.extension=jpg and fs.uid=my_uid and fs.type=Media");


Community Manager
Community Manager

Re: Is it possible to get the medias by type (such as PDF, doc, png)?

Hello Kavin,

do you need further help or did the given answers already help you? If so it would be great if you mark the "correct answer".

If you have already found a solution by yourself it would be very kind of you, if you posted it here.

Best regards


0 Kudos