How to upload a file via API and get it's URL?

Hello, I want to upload a file(not an image) via the API and get the URL back. How can I accomplish this?
I tried the solution provided here: but it seems that it is no longer up to date.

See How to reverse engineer the Discourse API


Also interested in this question
I can’t find a way to upload a file to Topic and Post via the API.
Perhaps someone can suggest a method.

I figured it out, the method is described in the documentation and it works.

  1. Upload a file using “/uploads.json”, in response we get the Short URL of the uploaded file like “upload://ueNyWDEgHhXIuIdB472fy9T6.txt”
  2. We update the post with the second API request, adding a line like this to the very end of post[raw]:
    [filename.txt|attachment](upload://ueNyWlEgHhXIuIdB472fy9T6.txt) (1.83 KB)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.