I have a page that allows to show an image when an item is selected (from a drop down).
There is a thousand of items (and the same number of images). The ID of the item is exactly the same as the name of the image ( Example Item ID = 12345, image ID = 12345.jpg)
What I want to do is make a query on “Media/files” (in a specific folder but this is not an issue) to find the ‘file URL’ for displaying it, by filtering on the ‘originalfilename’
Unfortunately, this ‘originalfilename’ cannot be filtered !!!
As a work around, I wrote a routine that reads ALL the records of the Media/files directory, and stored the originalname and the file URL in a customer collection. But this is very heavy, knowing that some of these photo can be updated often. For each update, I have to run the full routine.
Is there a chance that the ‘originalfilename’ becomes soon available for filtering, or is there another way to achieve this functionality
You could maybe do something using the listFiles()
API - https://dev.wix.com/docs/velo/api-reference/wix-media-v2/files/list-files
For example, list all of the files in a folder as you intend, then using code filter the array of data to find the object you want which should include the info you need to for the download URL
Thanks for this proposal. I created the backend function and it works. I receive the first hundred records of the thousand existing. (and the URL is included)
I am not really interested to receive all of them, but only the one with a known “displayname” (I have to check for duplicates and I know how to do that).
You mention a code filter. What do you exactly mean? a filter I can apply in the backend fonction, for exemple at the “options” definition, or a manipulation at the array level when all data has been retreived.
I already use the options to define the folder
I had a look at the “searchfiles” function from wix-media.v2, and use a search criteria option.
It seems to work BUT the search option has a strange behaviour:
If I search “PN1.jpg”, the results include also PN11.jpg, PN12.jpg,…up to PN19.jpg
if I search “Pi_376.jpg”, it also includes Pa_1376.jpg: strange !!
Any idea to improve this. Is that a bug in WIx?