Empty Image is uploadded

元气小坏坏 提交于 2019-12-13 02:50:35

问题


Image Upload to wordpress is uploading empty image

I am working on a mobile application consumes wordpress API. My application uses Nativescript-Vue Framework. I need to upload multiple images to wordpress using remote WP-API.

        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)
          })
    }

Unfortunately, Word Press receives an empty image. Any solution, i have tried nativescript-background-http.That does not work either, it has a lot of problems with oauth with wordpress


回答1:


As of today, {N} doesn't support multi-part data upload out of the box. You may follow on the open feature request on Github for further updates.

It's recommended workaround is to use nativescript-background-http plugin meanwhile.

tns plugin add nativescript-background-http


来源:https://stackoverflow.com/questions/56935875/empty-image-is-uploadded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!