I am having this exact question, asked in 2015, about adding media through the WP REST API.
My code so far:
curl -s -X POST http://www.example.com/wp-json/wp/v2/media/ -H "Content-Type: application/json" -H "Content-Disposition: attachment; filename=image.png" -H "Authorization: Basic $base64credentials " -d '{"title":"mymedia", "alt-text":"", "caption":"", "description":"", "slug":"myslug", "status":"publish", "date":"2019-01-16T00:00:00", "post":$id}'
My result so far:
{"code":"rest_upload_sideload_error","message":"Sorry, this file type is not permitted for security reasons.","data":{"status":500}}
When I replace the extension by .txt
, the call works, even if the file do not exist (??), and generates a corrupt empty media object.
Other calls for post creation and post updates work fine.
By switching into https
server, and using the curl -k
option, the same happens.
Do a Basic Authorization or HTTP or HTTPS problem might be the cause?
How should this be done today?
I am missing some header or syntax?
ssh
this is almost trivial?