【问题标题】:Empty Image is uploadded已上传空图像
【发布时间】:2019-07-08 13:21:43
【问题描述】:

图片上传到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 有很多问题

【问题讨论】:

    标签: wordpress vue.js axios nativescript


    【解决方案1】:

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

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

    tns plugin add nativescript-background-http
    

    【讨论】:

    • 但是我在使用 nativescript-background-http 时遇到了 jwt 的身份验证问题。你有这样的例子吗?
    • 你可以很容易地传递headers,只需参考插件的自述文件。
    猜你喜欢
    • 1970-01-01
    • 2021-03-15
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多