Add images to API posts

How to add pictures or file to an upcoming topic?

have you solved this problem?

You should upload the file and get the url to the file, then post it.

r = requests.put()
p = "http:"+r.json()['url']

Hey, I tried using a third-party cloud bed to store images later, and then I used img tags to implement content in themes or posts because it saved space on the server.

Hi @FunnySmile I am trying to post an image to post using the img tag like below but it’s not showing?

<img src="https://unsplash.com/photos/JoZazcPhW5Y" />

Can you please help?

You may want to note that may cloud bed does not allow a third party web site calls, generally speaking, a part of the cloud returns the address of the bed, some are can call, but some not, they will generally give extra img tags special url, if not, may be the cloud bed does not allow a third party call, you can use the browser developer mode, Then select Network to see what errors are encountered with image loading.

You can just add the url to the image without any html img tags

https://unsplash.com/photos/JoZazcPhW5Y

like this

and discourse will onebox it. But that isn’t even a link to an image, that just link to a page on the unsplash.com website. You will need to use the actual link for the image:

https://images.unsplash.com/photo-1658603458978-4a32b8cdadb7?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3272&q=80

If you are using the api, you can include the image url in the ‘raw’ field of the post.

Hi @blake
I tried as suggested. Here is my post request body

When i saw the post, it looks like this (Just shows the link not the image). When i put the link in the browser, i can get the image

Regards
Chitta

Can you add the image url on it’s own line?

asdfasdfasdf https://stayrightcon.com/wp-content/uploads/2020/05/Stayright-logo_resolution-72ppi.png

asdfasdf

https://stayrightcon.com/wp-content/uploads/2020/05/Stayright-logo_resolution-72ppi.png

I am also trying to find the same thing…post image in post api. Though i followed the step to upload the image and then get the url…but how can we send url in payload. Sending it in raw field post it in words…is there any way we can have image field as well in posts api? Please help

I’m sorry that I don’t understand your meaning at the moment. My follow-up solution is to use a third-party cloud image bed to upload the picture first and then return a picture url address.

<img src="url" />

Correct. Pass it in as a markdown link.

![image|581x455](upload://c4MB1Yzppr5Omv68MoJBQINqqiB.png)

Nope, because this is the same workflow that is used in the composer UI. You will have to make two api calls, one for the upload and the other to include the URL in post payload.

1 Like

Yeah correct, This is how i implemented this… just pass
“[image|581x455(upload://c4MB1Yzppr5Omv68MoJBQINqqiB.png)” in raw in post api. Here
1)image-any name you want to give
2)upload://c4MB1Yzppr5Omv68MoJBQINqqiB.png- this is the shorturl we get while uploading the image using upload api.

for steps: 1)first we have to upload the image using /upload.json api
step 2) pass the short url in above format with other post content in ‘raw’ field.

Thank you for your reply @blake

2 Likes