Placeholder for non existing remote images


I imported 80.000 posts from phpBB to Discourse. In the posts there are a lot of images linked from remote website like [img]http://www.domain.tld/image.jpg[/img] which are not there anymore.

The post does not show anything there, which causes irritations, as the context breaks in some of these posts as it is not clear that between the one and the next text block there is/was an image.

So my question is: Is it possible to get a placeholder image there if the original image is not available anymore?


Does it show the default broker image icon? I think it should after the posts are baked.

I customized mine. See (code included):

1 Like

No, it does not show anything. But I am getting closer. I think it is caused by the BBCode tag. If I edit a post and remove the tag, it looks like this.

So I would need to remove all [img] BBCode tags and rebake the posts?

That looks interesting. I think I need that, too. :slight_smile: Thank you!

I’m not sure. If you remove an inline BBcode tag then you’ll have the image URL in plain text inside your text, and it won’t use the broken image icon.

Maybe you could try removing the BBcode tag, but while inserting an empty line before and after the image URL. Do a backup first!

Yeah. Damn, you might be right.

Well, what would I need to change to get the broken image icon - or the remote image (my guess then downloaded) if it still exists?

I’m not sure.
I should have encountered this issue too since I’ve imported as well a phpBB forum with [IMG] tags and 95% of broken images, but from what I remember, after baking broken inline images were properly replaced by the broken image icon even when they were inline, but I could be wrong :thinking:

I’m afraid I don’t have any out-of-the-box solution for now, but I’m sure there’s a way to figure it out.

Do you have by chance a link to a message that would contain a broken inline image? Could you copy-paste the raw text as well?

1 Like

Sure, this is an live example:

If you check the first post, there is a big blank space below the last line of text and the signature. In the sourcecode you can see the dead images, e.g.:

<p><img src="" alt="" role="presentation" loading="lazy"></p>

“raw” from the database:


“cooked” from the database:

<p><img src="" alt="" role="presentation"></p>

Do you have download remote images to local setting enabled? The broken image icon appears only after Discourse tries to download the remote image and fails.

If the setting is disabled, it leaves an empty line.

Yes, it is enabled. Always was, also before I imported from phpBB.

Is it possible that the phpBB importer does not care for this setting? In my understanding the cooking should take place outside the importer and use the settings.

Does recooking all posts do any harm?

I tried:

rake posts:rebake_match["[img]"]
      767 / 767 (100.0%)
767 posts done!

The post I mentioned above (and it looks like all other) look exactly the same…

I think there’s a setting in /var/discourse/shared/standalone/import/settings.yml where we can set remote image download to true or false, but the posts will be baked after the import whether this option is set or not.

I see that your empty lines now show the expected broken image icon:

Instead of rebaking a bunch of posts, a good test is to rebuild a specific post HTML from the post admin options, since it triggers a rebake:


And then trigger the UpdateHotlinkedRaw job by adding it to the queue:

I tried on my test instance using one of your broken images and inside BBcode. When download remote images to local was disabled, the empty line stayed. When it was enabled, the broken image icon appeared instead.

1 Like

Oh yes, you are right. I think that was a browser cache problem after the rebake command. Thank you for checking yourself! :slight_smile:

So it was a phpBB import issue somehow. I would swear that I did not alter any config settings related to remote images after importing everything from phpBB…

Ah cool. I found it and I clicked onto it.

I cannot find a UpdateHotlinkedRaw job anywhere in Sidekiq… Can you help me sort that out. I’m sure that’s somehow PEBCAK. :wink:

That would lead into the direction that I enabled download remote images to local after importing everything from phpBB. Hm… As I also had/have a test installation and tested a lot of stuff there I am still pretty sure that it already was turned on before.

Note: the job would be triggered in a few minutes anyway, going to Sidekiq is just a way to check things faster.

The UpdateHotlinkedRaw job should be present seconds after you rebuild your post HTML, in the Scheduled tab of Sidekiq.

The job should be only visible if download remote images to local setting is enabled in your Discourse forum settings, and if your post contains image(s).

If that doesn’t work, then I don’t have any other idea for now…!

Thank you, than it is clear. I just rebaked any post - one without remote images. So nothing happened. :wink:

And thank you, you helped me sort things out here. I see the placeholder images now. And I most likely will replace the placeholder image with your css trick you linked here.

1 Like