I am trying to retrieve the Data URL of a picture saved to iPhone local storage in Ionic Native, running on real device, not simulator.
I am using File.readAsDataURL
I used X-code to look into my phone’s local storage and I can see the image at this location.
/var/mobile/Containers/Data/Application/* My APP ID */Documents/www/assets/images/image.png
Here is my code:
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { File } from 'ionic-native';
declare var cordova: any;
@Component({
selector: 'get-picture',
templateUrl: 'get-picutre.html'
})
export class GetPictureComponent {
fs:string = cordova.file.documentsDirectory;
constructor(
public platform: Platform
) {}
ionViewDidEnter() {
this.platform.ready().then(() => {
console.log("FileSystem", this.fs); //logs FileSystem file:///var/mobile/Containers/Data/Application/* My APP ID */Documents/
File.readAsDataURL(this.fs, 'www/assets/images/image.png')
.then((imgData) => {console.log('Image Data', imgData)})
.catch((error)=> console.log('error', error)); //Logs error {"code":1,"message":"NOT_FOUND_ERR"}
});
}
}
I have tried basically the same thing with
window.resolveLocalFileSystemURL(file:///var/mobile/Containers/Data/Application/* My APP ID */Documents/www/assets/images/image.png
and I get error code 1 again.
I updated my config.xml file with these preferences:
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" />
Does anyone know why this would not be working?
Ionic Version - 2.1.14
Thanks in advance!