首页 > 解决方案 > 节点 WPAPI 媒体无法上传“rest_upload_no_data”

问题描述

我在节点 WPAPI 中遇到问题。它不会上传照片。

它可以创建帖子,但不能上传图片(internal 、 uri 和 file:// path ),这些都不起作用。

给我带来问题的是自定义图像字段,其中包含可重复类型的图像和描述。

错误消息是“rest_upload_no_data”。为什么它无法接收数据?

 await wp.setHeaders({ Authentication: `Bearer ${token}` });
  // Selection
  await wp
    .createMission()
    .create({
      title: 'testing11111',
      status: 'publish',
    })
    .then(async (post) => {
      console.log('come to result');
      console.log(post);
      const filePath = '../images/note.png';
      return wp
        .media()
        .file(filePath)
        .create({
          title: 'Amazing featured image',
          post: post.id,
        })
        .then((media) => {
          console.log(`Media uploaded with ID #${media.id}`);
        });
    })
    .catch(async (err) => {
      console.log(err);
      const error = err.message;
      throw error;
    });
});

标签: javascriptimage

解决方案


推荐阅读