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: Using the Discourse API to post with uploaded files? but it seems that it is no longer up to date.

See How to reverse engineer the Discourse API