从nativescript-vue应用程序上传图像失败
我正在处理使用wordpress API的移动应用程序。我的应用程序使用Nativescript-Vue Framework。我需要将图像上传到wordpress媒体,Word press需要jwt oauth才能获得上传图像的权限,我尝试了axios以便使用API上传图像,但似乎nativescript可以不支持本文Empty Image is uploadded中所述的分段上传。我正在尝试使用nativescript-background-http。但这也不起作用。
uploadImages:function()
{
let session = bghttp.session("image-upload");
let request = {
url: 'http://mah.ttawor.com/wp-json/wp/v2/media',
method: 'POST',
headers: {
Authorization: this.auth_token,
'content_type':'multipart/form-data' ,
'Content-Disposition':`attachment; filename="product.jpg"`
},
description: "Uploading File to Wordpress Products"
};
var params = [];
let counter = 0;
this.product.images.forEach(i => {
params.push(
{
name:'Product' + (++counter),
file: i.src.android,
mimeType:'image/jpeg',
}
);
console.log(params.length);
});
let task = session.multipartUpload(params, request);
task.on('error', e => {
console.log('error====>>>>', e);
});
task.on('complete', e => {
console.log('complete', JSON.stringify(e));
});
}
`
很遗憾,我收到以下错误: `
JS:'error ==== >>>>'{eventName:'error',JS:object:JS:{ _observers:{错误:[对象],完成:[对象]},JS:_session:{_id:'image-upload'},JS:_id:'image-upload {1}',JS:_description:'上传文件到Wordpress产品”,JS:
_upload:0,JS:_totalUpload:1,JS:_status:'错误'},JS:错误:JS:{构造函数:JS:{[功能] JS:
[length]:0,JS:[name]:'',JS:[arguments]:null, JS:[调用方]:空,JS:[原型]:[对象],JS:
扩展:[对象],JS:空:[循环],JS:类: [Object]}},JS:responseCode:-1,JS:response:null}
有人可以帮我吗