I have successfully uploaded an image from the gallery, but I am facing issues while uploading multiple images at once.
Here is the code snippet I am using:
pictureUpload(x){ // x represents the file path like - file:///storage/emulated/0/Download/palakkeni.jpg
if(this.network.noConnection()){
this.network.showNetworkAlert()
}else{
let loading = this.loadingCtrl.create({
spinner: 'bubbles',
content: 'Uploading your Picture...'
});
loading.present();
var fileArray = x.split("/");
let len = fileArray.length;
var file = fileArray[len - 1];
let fileTransfer: FileTransferObject = this.transfer.create();;
let option: FileUploadOptions = {
fileKey: 'img',
fileName: x,
mimeType: "multipart/form-data",
headers: {
authorization : 'e36051cb8ca82ee0Lolzippu123456*='
},
params: {
name: file,
id: this.empid
}
}
this.completed = false;
fileTransfer.upload(x, encodeURI("http://forehotels.com:3000/api/upload_employee_image"), option, true)
.then((data) => {
this.completed=true;
loading.dismiss()
console.log("image uploaded")
}, (err) => {
loading.dismiss()
console.log(err)
let alert = this.alertCtrl.create({
title: err.text(),
subTitle: err.json(),
buttons: ['Dismiss'],
});
alert.present();
});
this.view_picture = file;
this.picture=x
this.uploaded++
}
}
The error output I'm receiving is as follows:
FileTransferError
body: null
code: 3
exception: "Permission denied (missing INTERNET permission?)"
http_status: null
source: "file:///storage/emulated/0/Download/xyz.jpg"
target: "http://companydomainname.com:3000/api/upload_employee_image"
Here is the output of 'ionic info' on my system:
Ionic:
Ionic CLI : 5.1.0 (C:\Users\pramo\AppData\Roaming\npm\node_modules\ionic) Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.2.4
Cordova:
Cordova CLI : 9.0.0 ([email protected]) Cordova Platforms : android 8.0.0, browser 5.0.4 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 1.2.1, (and 18 other plugins)
Utility:
cordova-res : 0.4.0 native-run : 0.2.6
System:
NodeJS : v10.15.3 (C:\Program Files\nodejs\node.exe) npm : 6.4.1 OS : Windows 10
The list of cordova plugins installed in my project includes:
cordova-android-support-gradle-release 3.0.0 "cordova-android-support-gradle-release"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-calendar 5.1.0 "Calendar"
cordova-plugin-contacts 3.0.1 "Contacts"
....
If anyone can guide me on why I am encountering this error and help resolve it, I would greatly appreciate it.