首页 > 解决方案 > 已上传空图像

问题描述

图片上传到 wordpress 正在上传空图片

我正在开发一个使用 wordpress API 的移动应用程序。我的应用程序使用 Nativescript-Vue 框架。我需要使用远程 WP-API 将多个图像上传到 wordpress。

        var data=[];
        const params = new FormData();
        //params.append('file', this.value);

         this.product.images.forEach(i => {
           params.append('file',i.src);
           console.log(i.src);
         });

        const axiosInstance = axios.create({
          baseURL: 'https://mah.ttawor.com/wp-json/wp/v2/',
          timeout: 5000,
          headers: {
            Authorization: this.auth_token,
            'content_type':'multipart/form-data' ,
            'Content-Disposition':`attachment; filename="product.jpg"`
          },
        });

        if(this.product.images.length === 0) return;


        axiosInstance.post('media',params)
          .then(response => {
            //console.log(response)
          })
          .catch(err => {
            console.log(err)
          })
    }

不幸的是,Word Press 收到一个空白图像。任何解决方案,我都尝试过 nativescript-background-http。那也不起作用,它与 wordpress 的 oauth 有很多问题

标签: wordpressvue.jsaxiosnativescript

解决方案


截至今天,{N} 不支持开箱即用的多部分数据上传。您可以关注 Github 上的开放功能请求以获取更多更新。

建议的解决方法是同时使用nativescript-background-http插件。

tns plugin add nativescript-background-http

推荐阅读