admin管理员组文章数量:1195902
How to Upload Media via the WP REST API ?
I am trying to upload media to
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!
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!
1 Answer
Reset to default 2If you still don't have a solution using Postman, I was able to send .png format image by configuring with these headers in POST:
And then in the body you select the binary option. So that worked for me.
本文标签: WordPress REST Upload Media
版权声明:本文标题:WordPress REST Upload Media 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738529341a2093291.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
source_url
andpost
as the payload? That doesn't sound correct at all. You should just pass the file itself in the body. See also this duplicate question. – swissspidy Commented Feb 21, 2018 at 14:05file
instead ofsource_url
– linktoahref Commented Feb 22, 2018 at 11:40