In a discussion about uploading images to Discourse plugins or themes for use in Glimmer components, bitmage explains the challenge of obtaining deterministic URLs for uploaded images — both in themes (via about.json) and plugins (via uploaded_image_list) — since Discourse stores uploads using content-based SHA1 hashes. pfaffman confirms that URLs are not user-settable but are based on file hashes, referencing a meta topic on asset inclusion. RGJ clarifies that while URLs aren’t manually set, they are deterministic: the same file will always generate the same hash and URL path (e.g., /uploads/<instance>/original/1X/...), though the subdirectory depth (1X, 2X, etc.) depends on upload volume. Alteras offers a solution for plugins: placing static assets in the /public directory makes them accessible via predictable URLs under the plugin’s namespace (e.g., /plugins/plugin-name/asset.png), without needing registration in plugin.rb, as demonstrated by the Discourse Math plugin. This approach suits non-configurable, hard-coded assets.
I would like to upload image icons as a part of my theme or plugin (I use both). I will then be referring to them from a glimmer component in the plugin. I need to be able to get the string URL of the image location, because I’m sending it to another server in an ajax request. (The remote server embeds icons into QR codes, if you want to know.)
If I put my images in about.json in the theme, they don’t get placed in a deterministic location - instead there’s a hash in the URL. So I don’t know how I would refer to them outside of CSS, much less in the plugin.
If I put my images in an admin setting for the plugin as an uploaded_image_list, the locations are also indeterministic, and what’s more they end up in an array with no human readable name/tag/alias to refer to them by.
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?
This question also pertains to any other assets that a person would want to upload. Both the assets section of about.json as well as the register_asset function to be used in plugin.rblook like they should be able to handle other file types than fonts, but if those files are getting uploaded I have no idea where they are.