Cordova file plugin not working

Hi,

i have added the cordova-plugin-file to my project, but it does not seem to work. At least, when I try window.resolveLocalFileSystemURL it throws an undefined function error.
This code is inside the platform.ready event. Do I need to do anything else in ionic 2 to get this working?

I am trying this in the browser (ionic serve). The plugin states that it supports the browser as well.

Joachim

1 Like

Hy guys i have the same problem, but im trying it on an android device and i still get “window.resolveLocalFileSystemURL” undefined:
“Object [object global] has no method ‘resolveLocalFileSystemURL’”

Anyone knows why?

I’ve been having the same problem, I get the same error “window.resolveLocalFileSystemURL is not a function” both using ionic serve, and on android. This is quite frustrating…

Any suggestions?

Sorry if this is a silly question, but are you certain you have added the plugin after the platform?

i have same question

hey guy, i found a solution, it’s working on ionic beta 10

import {Camera, File} from "ionic-native";
declare var window;

......
window.resolveLocalFileSystemURL(imageData, (entry)=>{
       console.log(entry);
});

// entry.toInternalURL() => cdvfile://localhost/assets-library/asset/asset.JPG?id=78EE38D3-34C1-4752-983B-6E20EAFF87AD&ext=JPG

// entry.fullPath => file:///asset/asset.JPG?id=78EE38D3-34C1-4752-983B-6E20EAFF87AD&ext=JPG

but i can’t show image using that

1 Like

Any idea how I can use it in beta 11

i belive it will work with beta 11

Same problem on ionic 2.0.0-rc.0

window.resolverLocalFileSystemURL can only be used once platform is ready:

platform.ready().then(() => {
    window.resolveLocalFileSystemURL(path, (dir) => {
    ...
    }
});

Don’t forget to import Platform from “ionic-angular”.

1 Like

Having this issue with ionic 2, has anyone properly solved this? i am using the CamerPreview plugin and am just trying to display the captured image.

Hi Joachim,

You can try the following code.

File.resolveLocalFilesystemUrl(imageURI).then((fileEntry) => {

   this.imgUrl = fileEntry; // "img/bg1.jpg" ;

});

Don’t forget to import the File from the ionic-native.

Good Luck

1 Like

use this, import { File, Entry } from ‘@ionic-native/file’;

did you ever get the resolved have the same issue on ios. works fine on android

you ever resolve this facing the same issue

it returns empty directory list,

  var myPath = cordova.file.externalRootDirectory; // We can use the default externalRootDirectory or use a path : file://my/custom/folder

window.resolveLocalFileSystemURL(myPath, function (dirEntry) {
	console.log(dirEntry);
     var directoryReader = dirEntry.createReader();
     directoryReader.readEntries(onSuccessCallback,onFailCallback);
});

function onSuccessCallback(entries){
  console.log( 'The magic will happen here, check out entries with');  
   console.log(entries);
}

Hi @nanthang! Thank you for sharing. Do you happen to know how to translate the code you provide to Ionic version 1?

File.resolveLocalFilesystemUrl(imageURI).then((fileEntry) => {
  this.imgUrl = fileEntry; // "img/bg1.jpg" ;
});