See
for an example of using the new image upload API in Discourse. It’s for a different purpose but the same probably applies.