How to Upload Media via the WP REST API ?
I am trying to upload media to
http://example.com/wp-json/wp/v2/media
using POSTMAN.
I tried uploading image using the following headers
Content-Type: image/jpeg
Content-Disposition: attachment; filename=name.jpeg
and the payload I am sending is
source_url: (file) Uploaded File
post: (text) Post Id
and the response that I’m getting is
{
"code": "rest_upload_unknown_error",
"message": "File is empty. Please upload something more substantial.
This error could also be caused by uploads being disabled in your php.ini or
by post_max_size being defined as smaller than upload_max_filesize
in php.ini.",
"data": {
"status": 500
}
}
and When I tried sending the file path instead of the file like
source_url: (text) file:///C:/Users/Username/Pictures/01.jpg
post: (text) Post Id
I get the response as
{
"code": "rest_upload_no_data",
"message": "No data supplied.",
"data": {
"status": 400
}
}
I tried uploading image via the web dashboard and it works. Just got no clue as to how to make it work via the API.
Any suggestions or help appreciated!
Thank You!