这是我用来将图像传输到服务器的功能。它正在使用http url现在它在https url上提供了异常。我认为因为cordova文件传输插件仅支持http而不支持https。任何人都可以帮我解决这个问题,因为其他事情依赖于它。
public uploadImg(img, userId) {
/*if (credentials.email === null || credentials.password === null || credentials.name === null) {
return Observable.throw("Please insert credentials");
} else {*/
// At this point store the credentials to your backend!
console.log(userId);
let options: FileUploadOptions = {
fileKey: 'img',
fileName: 'name.png',
params: {action: 'upload_image', api_key: API_KEY, user_id: userId},
httpMethod: 'post',
mimeType: 'image/png'
}
console.log('upload function');
return new Promise(resolve => {
this.fileTransfer.upload(img, encodeURI('https://pehlayzindagi.pk/api/api.php'), options)
.then((data) => {
console.log('uploaded image');
console.log('APi response is' + data.response);
let img = JSON.parse(data.response);
console.log(img.status + ' ' + img.message);
resolve(img)
// success
}, (err) => {
console.log('image failed');
reject(false)
// error
});
});
// } }
由于
答案 0 :(得分:0)
This主题帮助了我,最终找到了解决方案。我正在回答这个问题,所以它可以帮助别人。您需要在选项中添加此chunkedMode = false参数,然后它也将与https一起使用。干杯!