Reputation: 169
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!
Upvotes: 4
Views: 2202
Reputation: 169
I did a little bit more digging into this issue.
First I did a File.listDir()
at my root documents directory (cordova.file.documentsDirectory)
. I found that the the only folder in the documents directory, that the File System could see, was "NoCloud"
.
Even though Wikitude is successfully putting images in a folder in this directory called "/www/assets/images/"
the file system cannot see, write, or read to it.
I set up wikitude to save images into the "NoCloud" folder and now I can successfully use File.readAsDataUrl()
to get base64 image data from the "NoCloud" folder.
Hope this helps someone.
Upvotes: 2