问题
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