PhoneGap/Cordova Tip: Working with files under www and Android

This post is more than 2 years old.

This is a topic that has come up a few times in comments recently but I wanted to post something a bit more explicit. First and foremost, you cannot use the File system APIs to work with files under the www folder. The docs for the File plugin incorrectly states that you have Read access to the application directory (which would contain www) but that is incorrect.

You can use XHR to read in files from under www. For text files this is rather trivial. For binary data you want to be careful before reading in large amounts of data. Remember that you can work with binary data via Ajax using XHR2 (spec and support levels).

Finally - one problem you may run into is supporting a dynamic list of files. Since you can't read the directory, if you want to support a random set of assets under www then you would need to ship a file that contains a list of those resources. You would then do an XHR to that file, get the list, and process as you see it.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Sergei Fedorenko posted on 1/27/2015 at 6:31 AM

Hi, thank you for yours great articles!!!

-->> ... you can’t read the directory ...
https://github.com/007-sura...
This plugin allow me read list of files in my App

Comment 2 by Sergei Fedorenko posted on 1/27/2015 at 6:53 AM

and what you mean resources files in cordova project, it's special status for files like "ResourceFiles"?

For example www/img it's usual content, but www/mySameFolder can be have status of "ResourceFiles"?

Comment 3 (In reply to #2) by Raymond Camden posted on 1/27/2015 at 11:39 AM

I didn't mean anything formal - just abstract.

Comment 4 (In reply to #3) by Sergei Fedorenko posted on 1/27/2015 at 12:54 PM

)))!! I started looking into Google 'variants for including files in Cordova project'
Though, this question is more about possibilities of native platforms like IOS, Android ...