1

I'm successfully using the .search element attribute to search asset filenames stored locally.

{% set mediaExists = craft.assets.folderId('6').search('filename:' ~ vLogID|slice(0, 5)) %}

Is it possible to search filenames stored on a remote Amazon S3 volume?

In my testing, it doesn't seem to be finding the remote files. It works when searching the local volume folderId('3') by not when the remote S3 folder folderId('6').


Background: There is no direct relationship between an entry and assets. I upload all assets to the server via FTP and then index the volume in my Craft Control Panel. I can see the S3 asset in Craft CP and have cleared cache and reindexed the S3 folder source.

I am using a url query string to tell the template what the LogID is for the entry that is displayed. Then, the code searches the asset folder for any assets that contain that LogID number. If there are any matches, then those assets are displayed on the front end page in a slider.

I can see the S3 asset if I type in the direct asset url link so the permissions of Public seem to be set correctly.


This is my code that is searching the asset filename on the server:

<!-- grab log id and use slice filter  -->
{% set vLogID = craft.app.request.segments|last %}

<!-- Check to see if there is any media uploaded  -->
{% set mediaExists = craft.assets.folderId('6').search('filename:' ~ vLogID|slice(0, 5)) %}

The above code says:

Grab the LogID from the url query string (example: 12345).

Then, search the asset folder (set by folderID), search all of the files in the folder for any filenames that contain LogID (example 12345).

It works when searching the local volume folderId('3') but not when the remote S3 folder folderId('6').

  • It should work the same. Regardless of if the volume is local or remote, when you use .search(), it's actually searching against the searchindex table in the database. If you search that table, do you see the filename as a search keyword for what you're searching for? Also, what is the filename? – Brad Bell Dec 6 '18 at 23:40
  • @BradBell One file name is: "20180919-15472-993-vid-01.mp4" Yes, when I search the searchIndex table "keywords contains" and type in the LogID "15472" I see them all. Here's a screenshot: d.pr/i/gJfAS9 and here's a screenshot of the "craft_assets" table showing the files in both the local and S3 source folders: d.pr/i/baJRO4 – Lori Dec 6 '18 at 23:47
1

I figured it out. I was using folderID instead of volumeID. It looks like this parameter changed from Craft 2 to Craft 3.

|improve this answer|||||

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.