我试图通过WP v2发布/上传一个新媒体(WP 4.7.3)。我使用Node (https://github.com/WP-API/node-wpapi)来处理这个问题。
由于我只收到错误400 rest_upload_no_data,所以我试图找出执行此操作所需的字段。
我在做的是:
wp.media()
.file( uri )
.create({
title: 'My awesome image',
alt_text: 'an image of something awesome',
caption: 'This is the caption text',
description: 'More explanatory information',
status: 'publish'
})
.then(function( response ) {
...我检查了docs (https://developer.wordpress.org/rest-api/reference/media/),但是我看不出需要哪一个param。
有什么帮助吗?
发布于 2017-05-22 17:26:44
此问题可能是.file()方法期望缓冲区或本地文件系统路径(如果在节点中运行),或者期望输入字段中的文件对象(在浏览器中运行时)。URI字符串不能解释为图像,因此不发送图像数据,从而导致“无数据”错误。
如果在浏览器中运行此库,则可以使用输入的file对象发送图像:
var data = document.getElementById( 'file-input' ).files[0];
wp.media().file( data )...据我所知,WordPress REST不支持侧加载映像,因此要上传远程映像,首先必须检索它,然后将数据转发给API自己。
编辑以包含指向节点-wpapi库的文件上载文档的链接:
https://stackoverflow.com/questions/43662293
复制相似问题