Is there a way to get the absolute path of an image in phonegap asset folder?
I need the absolute path to attach the image in a mail using EmailComposer plugin.
It looks like this is not possible.
See https://groups.google.com/forum/#!topic/phonegap/Sw2wThOYm8c
From Simon's response in that thread he states...
"You can't do what you want to do. The files in the assets directory are not technically on the file system so they are not accessible via the File API. This means calling window. resolveLocalFileSystemURI() will not return you a FileEntry. It is properly returning an error code of 1 which is NOT_FOUND_ERR. "
You need the absolute path of a file for the email attachments plugin to work. Unfortunately if the file resides in the assets folder, you cannot use cordova's file api to get the absolute path.
There is a plugin that exists to copy files out of your assets folder and place them onto the sdcard. You can then pass the exact location of this file to the email attachments plugin. Unfortunately it looks like the plugin below is out of date if you are planning on using the newer cordova versions.
https://github.com/gkcgautam/Asset2SD
Pass 'file:///android_asset/www/img/logo.png' to window.resolveLocalFileSystemURI() and the resulting FileEntry.fullPath is what you want. Look at the documentation for detailed example: http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html
Just in case somebody is still looking for a solution. Now Cordova implements a really easy way to get the current application directory (supported on Android, iOS and BlackBerry 10) :
cordova.file.applicationDirectory
For example, if you want to access an audio file in your res/audio
directory (within your www
), you just have to write that :
cordova.file.applicationDirectory + 'res/audio/my-audio-file.mp3'
Here is the complete documentation