问题
I am trying to upload an image using ionic 4 and ios.
The error I keep getting is:
TypeError: undefined is not a constructor (evaluating 'new _ionic_native_file_ngx__WEBPACK_IMPORTED_MODULE_2__["FileReader"]()')
Here is the relevant code:
startUpload(imgEntry) {
this.file.resolveLocalFilesystemUrl(imgEntry.filePath)
.then(entry => {
(<FileEntry> entry).file(file => this.readFile(file));
}).catch(err => {
this.presentToast('Error while reading file.');
});
}
readFile(file: any) {
const reader = new FileReader();
reader.onloadend = () => {
const formData = new FormData();
const imgBlob = new Blob([reader.result], {
type: file.type
});
formData.append('file', imgBlob, file.name);
this.uploadImageData(formData);
};
reader.readAsArrayBuffer(file);
}
async uploadImageData(formData: FormData) {
const loading = await this.loadingController.create({
message: 'Uploading image...'
});
await loading.present();
this.http.post('http://localhost/upload.php', formData)
.pipe(
finalize(() => {
loading.dismiss();
})
)
.subscribe(res => {
if (res['success']) {
this.presentToast('File upload complete.');
} else {
this.presentToast('File upload failed.');
}
});
}
I am copying the app to my iphone 6 via xcode and then running the application, which runs fine but when I try to upload the image I get the error above.
How can I fix this error?
来源:https://stackoverflow.com/questions/57485613/ionic-4-file-upload-error-with-filereader-ios