# 上传图片到插件/主题的最佳方式？

**URL:** <https://meta.discourse.org/t/best-way-to-upload-images-to-a-plugin-theme/360581>\
**Category:** Development\
**Tags:** plugin-api\
**Created:** [2025 年4 月 6 日 02:39 UTC](https://meta.discourse.org/t/best-way-to-upload-images-to-a-plugin-theme/360581 "2025-04-06T02:39:10Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

作者： ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
发布日期： [2025 年4 月 6 日 21:47 UTC](https://meta.discourse.org/t/best-way-to-upload-images-to-a-plugin-theme/360581/3 "2025-04-06T21:47:54Z")

</div>

> [@bitmage](#):
>
> So is there a way I can upload images, either to the theme or plugin, in a way that they end up at a deterministic URL?

即使您无法_设置_URL，它也是_确定性的_，因为URL由文件的SHA1哈希组成。

只要您不更改文件内容，它应该会出现在以下任一位置：

```plaintext
/uploads/<实例名称>/original/1X/1764ca1c70c7f4f7f01da26e702639fd8cfe2bf4.jpeg

```

或者

```plaintext
/uploads/<实例名称>/original/2X/1/1764ca1c70c7f4f7f01da26e702639fd8cfe2bf4.jpeg

```

或者

```plaintext
/uploads/<实例名称>/original/3X/1/7/1764ca1c70c7f4f7f01da26e702639fd8cfe2bf4.jpeg

```

或者

```plaintext
/uploads/<实例名称>/original/4X/1/7/6/1764ca1c70c7f4f7f01da26e702639fd8cfe2bf4.jpeg

```

（具体是哪一个取决于您已有的上传数量（[https://github.com/discourse/discourse/blob/main/lib/file\_store/base\_store.rb#L230C1-L234C8](https://github.com/discourse/discourse/blob/main/lib/file_store/base_store.rb#L230C1-L234C8)）。

---

_[View the full topic](https://meta.discourse.org/t/best-way-to-upload-images-to-a-plugin-theme/360581)._
