我正在尝试使用转移,但显然出现了问题,我无法弄清楚原因。
我尝试按照文档(https://ionicframework.com/docs/native/transfer/)进行操作,但我无法使其正常工作!
我也在这里和离子论坛上搜索了许多答案,但没有任何效果!
这就是我所拥有的:
let headers = new Headers();
headers.append( 'X-DeviceAPIKEY', DeviceAPIKEY);
headers.append( 'X-DeviceACUID', AccountUID);
var url = this.BaseAPIurl+"UploadController.ashx";
// File for Upload
var targetPath = "./57826randomName.jpg";
// File name only
var filename = "57826randomName.jpg";
const fileTransfer: TransferObject = this.transfer.create();
let options: FileUploadOptions = {
fileKey: "file",
fileName: filename,
chunkedMode: false,
mimeType: "image/jpeg",
headers:headers,
params: {
filename:filename,
RUID: RUID,
MUID: MUID
}
};
this.loading = this.loadingCtrl.create({
content: 'Uploading...'
});
this.loading.present();
try {
// Use the FileTransfer to upload the image
fileTransfer.upload(targetPath, url, options).then(data => {
this.loading.dismiss();
this.presentToast('Image successfully uploaded.');
}, err => {
this.loading.dismiss();
this.presentToast('Error while uploading file.');
});
}
catch(err) {
console.log("ERROR",err);
}
当我在浏览器上运行它时,它似乎永远不会运行。装载元件永远不会被解雇。这里的静态路径适用于我的PC。当我在设备上运行它时,我改变了路径。在设备上它似乎运行但返回Error while uploading file.
为什么会这样?可能是因为路径?
我该如何使用这个插件?
非常感谢!