# Search attachments by storage name

**URL:** https://meta.discourse.org/t/search-attachments-by-storage-name/209945
**Category:** Support
**Created:** [November 23, 2021, 4:23am UTC](https://meta.discourse.org/t/search-attachments-by-storage-name/209945 "2021-11-23T04:23:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ivan\_Rapekas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ivan_rapekas/32/248924_2.png) [@Ivan\_Rapekas](https://meta.discourse.org/u/Ivan_Rapekas)
#### Post date: [November 23, 2021, 4:23am UTC](https://meta.discourse.org/t/search-attachments-by-storage-name/209945/1 "2021-11-23T04:23:44Z")

</div>

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:

 ![изображение](https://global.discourse-cdn.com/meta/original/3X/c/f/cfea6229c42952c36de255373bb7f7eadaf16f1a.png)

Untortunately search by storage name does not work:

 ![изображение](https://global.discourse-cdn.com/meta/original/3X/4/8/48e9afbf0e82fe115dc117cee66566e3cc54cee9.png)

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](https://meta.discourse.org/t/32566?silent=true) exists?

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 23, 2021, 4:32am UTC](https://meta.discourse.org/t/search-attachments-by-storage-name/209945/2 "2021-11-23T04:32:06Z")

</div>

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

```plaintext
Upload.sha1_from_short_url
Upload.sha1_from_short_path
Upload.sha1_from_base62_encoded

```

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:

```plaintext
Upload.find_by(sha1: sha_to_find)

```

In your case, if I typed it correctly:

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

```

---

<div class="post-metadata">

### Author: ![Ivan\_Rapekas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ivan_rapekas/32/248924_2.png) [@Ivan\_Rapekas](https://meta.discourse.org/u/Ivan_Rapekas)
#### Post date: [November 23, 2021, 7:11am UTC](https://meta.discourse.org/t/search-attachments-by-storage-name/209945/3 "2021-11-23T07:11:05Z")

</div>

> [@supermathie](#):
>
> `Upload.find_by(sha1: `

Hm, very interesting, many thanks! 🤝

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

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

```

 ![изображение](https://global.discourse-cdn.com/meta/original/3X/b/b/bbe669ac4ea0ab8c10b54aea9281731cf11aa086.png)

Also SQL for database:

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

```

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 23, 2021, 7:11am UTC](https://meta.discourse.org/t/search-attachments-by-storage-name/209945/4 "2021-12-23T07:11:19Z")

</div>

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