# How do I delete the file of user avatar?

**URL:** https://meta.discourse.org/t/how-do-i-delete-the-file-of-user-avatar/185321
**Category:** Support
**Created:** [April 3, 2021, 4:00am UTC](https://meta.discourse.org/t/how-do-i-delete-the-file-of-user-avatar/185321 "2021-04-03T04:00:26Z")
**Posts on this page:** 5
**Page:** 2

<div class="post-metadata">

### Author: ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)
#### Post date: [June 5, 2021, 2:14pm UTC](https://meta.discourse.org/t/how-do-i-delete-the-file-of-user-avatar/185321/21 "2021-06-05T14:14:49Z")

</div>

> [@pfaffman](#):
>
> After you make that stop sending the images

This is the goal that I have no idea how to achieve. As an iOS reverse engineer, my idea is that if I know in the source code how/where the server sends this image, I can track back and see where the server loads this image locally. But I read Ruby like reading seudo code, so locating where the server sends this image becomes a great great task for me 😭 That should be a lot easier for a person who’re familiar with the source code though

---

<div class="post-metadata">

### Author: ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)
#### Post date: [June 5, 2021, 2:46pm UTC](https://meta.discourse.org/t/how-do-i-delete-the-file-of-user-avatar/185321/22 "2021-06-05T14:46:49Z")

</div>

In [discourse/app/models/upload.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/app/models/upload.rb#L471)

I saw the table `uploads` which stored all the uploads of a user. For user `Baal998` whose user ID is `1637`, I then run `SELECT * FROM uploads WHERE user_id = '1637';` and the result is

```plaintext
  id | user_id | original_filename | filesize | width | height | url | created_at | updated_at | sha1 | origin | retain_hours | extension | thumbnail_width | thumbnail_height | etag | secure | access_control_post_id | original_sha1 | animated | verified | verification_status 
------+---------+-------------------+----------+-------+--------+-----------------------------------------------------------------------------+----------------------------+----------------------------+------------------------------------------+--------+--------------+-----------+-----------------+------------------+------+--------+------------------------+---------------+----------+----------+---------------------
 2210 | 1637 | 2.pic.jpg | 60610 | | | /uploads/default/original/2X/c/cb2188eaeecc3a648f021fa00da4734bd60ca183.jpg | 2016-08-08 09:37:13.937306 | 2018-01-05 02:38:49.498264 | cb2188eaeecc3a648f021fa00da4734bd60ca183 | | | jpg | | | | f | | | | | 1
(1 row)

```

Which is the same to running `Upload.find(user_avatar.custom_upload_id).url` with rails.

My guess is that after the user uploaded avatar, discourse will do something to the original avatar file and store the optimized files in somewhere else?

---

<div class="post-metadata">

### Author: ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)
#### Post date: [June 5, 2021, 3:13pm UTC](https://meta.discourse.org/t/how-do-i-delete-the-file-of-user-avatar/185321/23 "2021-06-05T15:13:45Z")

</div>

In table `optimized_images` this row seemed suspicious

```plaintext
  id | sha1 | extension | width | height | upload_id | url | filesize | etag | version | created_at | updated_at         
-------+------------------------------------------+-----------+-------+--------+-----------+----------------------------------------------------------------------------------------+----------+------+---------+----------------------------+----------------------------
 49538 | e6dc9b0d6c18f2a4c3c0d2027534d01cfc89c84e | .jpg | 135 | 135 | 2210 | /uploads/default/optimized/2X/c/cb2188eaeecc3a648f021fa00da4734bd60ca183_2_135x135.jpg | 10968 | | 2 | 2016-08-08 09:37:13.937306 | 2016-08-08 09:37:13.937306
(1 row)

```

The `sha1` and `filesize` matches [https://iosre.com/user\_avatar/iosre.com/baal998/135/2210\_2.png](https://iosre.com/user_avatar/iosre.com/baal998/135/2210_2.png), but on server this file doesn’t exist.

```plaintext
root@iosre:/var/discourse/shared/standalone# ls /uploads/default/optimized/2X/c/cb2188eaeecc3a648f021fa00da4734bd60ca183_2_135x135.jpg
ls: cannot access /uploads/default/optimized/2X/c/cb2188eaeecc3a648f021fa00da4734bd60ca183_2_135x135.jpg: No such file or directory

```

No idea what was wrong.

---

<div class="post-metadata">

### Author: ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)
#### Post date: [June 8, 2021, 5:03am UTC](https://meta.discourse.org/t/how-do-i-delete-the-file-of-user-avatar/185321/24 "2021-06-08T05:03:39Z")

</div>

Problem solved:

Someone from my [forum](https://iosre.com/t/topic/19791/14) told me that this avatar image might be stored in nginx cache under `proxy_cache_path`, which was usually `/var/nginx/cache`, but I couldn’t find either `proxy_cache_path` or `/var/nginx/cache`.

I was inspired by him that I entered the discourse app via `launcher enter app` and then found nginx cache:

```plaintext
root@iosre:/var/discourse/shared# /var/discourse/launcher enter app
WARNING: Docker version 17.05.0-ce deprecated, recommend upgrade to 17.06.2 or newer.
root@iosre-app:/var/www/discourse# cd /var/nginx/cache
root@iosre-app:/var/nginx/cache# ls
0 1 2 3 4 5 6 7	8 9 a b c d e f
root@iosre-app:/var/nginx/cache# 

```

And deleted all the caches:

```plaintext
root@iosre-app:/var/nginx/cache# ls
root@iosre-app:/var/nginx/cache# 

```

The image was gone.

---

<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: [July 8, 2021, 5:04am UTC](https://meta.discourse.org/t/how-do-i-delete-the-file-of-user-avatar/185321/25 "2021-07-08T05:04:09Z")

</div>

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

[Previous page](https://meta.discourse.org/t/how-do-i-delete-the-file-of-user-avatar/185321.md?page=1)
