【发布时间】:2018-02-17 14:43:57
【问题描述】:
这是我用来将图像传输到服务器的函数。它正在使用 http url,现在它在 https url 上给出了异常。我认为是因为cordova文件传输插件只支持http而不支持https。任何人都可以帮助我在 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://exampledomain.com/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
});
});
// } }
谢谢
【问题讨论】:
标签: cordova ionic-framework cordova-plugins cordova-3 ngcordova