2 Replies Latest reply on Sep 5, 2017 3:40 PM by zacharyr30798184

    Locating /img directory using window.resolveLocalFileSystemURL

    zacharyr30798184 Level 1

      I'm pretty new to working with Phonegap and have encountered a problem trying to find files/folders when working with the cordova.file plugin.

       

      I'm using Phonegap Desktop and testing on an Android device. I want to check my the app /img directory to see if a file exists, but I am having trouble finding the proper url of the directory. This /img directory is where all my index.html src links point to just to clarify.

       

      The following code produces a file found for 'index.html' :

       

      window.resolveLocalFileSystemURL(cordova.file.applicationDirectory, function (fs){

              fs.getFile("www/index.html", { create: false }, function (fe){

                          alert("file exists");

                      }, function(){

                          alert("file does not exist");

                      });

      }, function(){});

       

      However trying to search for something like 'www/img/file.png' doesn't work. Obviously I'm doing something completely wrong here as I don't have a firm grasp of where img resources are mapped. Where should I be referencing in order to view the /img directory contents on the device?

       

      Thanks in advance for any help or advice you can offer!

       

      EDIT: I forgot to mention that I am using the Phonegap Mobile App to test on the Android device.

       

      EDIT2: After some testing I have found a way to reference files using the 'cordova.file.dataDirectory'. After checking the document.url it appears the application files are stored in a directory "phonegapdevapp/www/". I checked this /img folder here and it works.

       

      window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (fs){

           fs.getFile("phonegapdevapp/www/img/file.png", { create: false }, function (fe){

                alert("file exists");

           }, function(){

                alert("file does not exist");

           });

      }, function(){});

       

      While this is fine for testing, I'm wondering how this will work when the app is actually deployed. Obviously I won't be referencing "phonegapdevapp/www/" in the actual build version. Is there a better way to reference this location?

       

      Again, sorry for so many updates and changes. I'm truly a beginner when it comes to Phonegap.