Search attachments by storage name

Hi, is it possible to search files in storage by their storage names?

I mean to find not by filename, but for its hash-based name which is related to attachment. For example, as an admin I explored forum backup and found some big attachment. I don’t know the original filename to be able quickly pick it in the forum to explore.

I can search by filename, and I see its storage name:

Untortunately search by storage name does not work:

Is any way to friendly operate these attachments? I don’t want delete them from the storage until explore their content (in most cases I would like to clean, trim content and repack them). Probably some method using Data Explorer exists?

What I think you need is to find the sha1 using one of the console methods:


the logic of which you can reproduce somewhere else if you need to. With that sha1 hash you can search the uploads table for the value, or use at the console:

Upload.find_by(sha1: sha_to_find)

In your case, if I typed it correctly:

[1] pry(main)> Upload.sha1_from_base62_encoded 'yl9oPeFdXA4DSdL4chS0sznm5zF'
=> "f0ae01b37fe5db52f1935f6247dff639f77c5117"

Hm, very interesting, many thanks! :handshake:

P.S. for those who will come to this topic from search:
How to run rails console (to initiate Pry session):

sudo /var/discourse/launcher enter app
rails c
pry(main)> here you may run commands posted above

Also SQL for database:

SELECT filesize, original_filename, sha1 FROM uploads WHERE filesize > 3000000 order BY filesize desc

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.