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

**URL:** https://meta.discourse.org/t/best-way-to-upload-images-to-a-plugin-theme/360581
**Category:** Development
**Tags:** plugin-api
**Created:** [2025年四月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:** 1

<div class="post-metadata">

### Author: ![bitmage](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bitmage/32/389881_2.png) [@bitmage](https://meta.discourse.org/u/bitmage)
#### Post date: [2025年四月6日 02:39 UTC](https://meta.discourse.org/t/best-way-to-upload-images-to-a-plugin-theme/360581/1 "2025-04-06T02:39:10Z")

</div>

我希望能够上传图像图标作为我的 **主题或插件** （我两者都使用）的一部分。然后，我将从插件中的 Glimmer 组件引用它们。我需要能够获取图像位置的字符串 URL，因为我将在 AJAX 请求中将其发送到另一个服务器。（如果您想知道，远程服务器会将图标嵌入到 QR 代码中。）

如果我将图像放在 **主题** 的 `about.json` 中，它们不会被放置在确定性的位置——相反，URL 中有一个哈希。因此，我不知道如何在 CSS 之外引用它们，更不用说在插件中引用了。

如果我将图像作为 `uploaded_image_list` 放在 **插件** 的管理设置中，位置也是不确定的，而且它们最终会出现在一个数组中，没有人类可读的名称/标签/别名来引用它们。

```plaintext
// console.log(this.siteSettings.county_fence_available_icons):
/uploads/default/original/1X/1764ca1c70c7f4f7f01da26e702639fd8cfe2bf4.jpeg|/uploads/default/original/1X/b16cecd70e4d25abdf06a8b6135ec126d2c6ce2d.jpeg|/uploads/default/original/1X/b4c049256c1068e531e43f1622ada78c5b2070b3.jpeg|/uploads/default/original/1X/4aa457c9cd939e178eb251682a4438cc027b96e9.jpeg

```

那么，有没有办法将图像上传到主题或插件，使其最终具有确定的 URL？

这个问题也涉及到一个人想要上传的任何其他资产。`about.json` 的 `assets` 部分以及 `plugin.rb` 中要使用的 `register_asset` 函数_看起来_都能够处理字体以外的其他文件类型，但如果这些文件被上传了，我不知道它们在哪里。

---

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