空图片已上传

时间:2019-07-08 13:21:43

标签: wordpress vue.js axios nativescript

图像上传到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中存在很多问题

1 个答案:

答案 0 :(得分:1)

截至今天,{N}不支持开箱即用的多部分数据上传。您可以在Github上关注open feature request,以获取更多更新。

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

tns plugin add nativescript-background-http