I’m trying to use moveFile function which is provided from file native plugin, i cannot upload screenshots since it’s a private project belongs to my company but i will try to explain as much as i can
I use camera native plugin to take photos, camera is working very well and the photos are showing, but when i try to use file native plugin (moveFile) method just to move taken photos to files directory rather than cache, nothing happens!
file and fileError are imported in the page TS, file is provided in App Module as well
Here is my TS:
onTakePhoto() {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
sourceType: this.camera.PictureSourceType.CAMERA,
cameraDirection: 1,
saveToPhotoAlbum: true
}
this.camera.getPicture(options).then((imageData) => {
const currentName = imageData.replace(/^.*[\\\/]/, '');
const path = imageData.replace(/[^\/]*$/, '');
const newFileName = new Date().getUTCMilliseconds() + '.jpg';
this.file.moveFile(path, currentName, cordova.file.dataDirectory,
newFileName).then(
data => {
this.imageUrl = data.nativeURL;
this.photoError = 'path is: '+path +' Current name: '+currentName +'
new file directory: '+ cordova.file.dataDirectory +' new file name is:
'+ newFileName+
' image name is: '+ this.imageUrl;
this.images.push(this.imageUrl);
this.file.removeFile(path, currentName);
}
).catch((e) => {
this.photoError = 'path is: '+path +' Current name: '+currentName +' new
file directory: '+ cordova.file.dataDirectory +' new file name is: '+
newFileName+
' image name is: '+ this.imageUrl;
})
}, (err: FileError) => {
this.imageUrl = '';
const toast = this.toastCtrl.create({
message: "Couldn't save the image, try again!",
duration: 2000
});
toast.present();
this.camera.cleanup();
});
}
My HTML
<ion-item>
<h5>Choose files to upload</h5>
<button (tap)="onTakePhoto()" item-end ion-button round outline
color="sideBar">Upload</button>
</ion-item>
<ion-slides *ngIf="images.length >= 1">
<ion-slide style="float: left;" *ngFor="let image of images; let i =
index;" class="image-container">
<ion-icon (tap)="onDeletePhoto(i)" class="icon-container" name="close-
circle"></ion-icon>
<img [src]="image" width="100">
</ion-slide>
</ion-slides>
<ion-item>
As you can see i tried to view the 4 parameters on the screen with the photoError string, and everything is looking very good, the old path is right, the name, the new path and new name is right, but the image is not moved from the pictures folder, i find the file folder on my phone is empty, and the image still in pictures folder, the imageUrl string is also showing the correct path of the image (the new one), when i try to set the imageUrl to the old path, also image is not showing, i tried the app on another Android device, also same issue so it’s not from my phone.
Anyone has any idea? if you have any questions that i didn’t provide an answer for, feel free to ask.