About
Blog
Projects
Contact

Cordova to Capacitor File Conversion

Cordova and Capacitor use different conventions and aliases to refer to standard directories on iOS and Android.

I checked the source code and here is how the different aliases map up:

Android Conversion

Device Pathcordova.file.*AndroidExtraFileSystemsCapacitor DirectoryAvailable with requestLegacyExternalStorageRestrictions on Android 11+Native Commandr/w?persistent?OS clearsprivate
file:///android_asset/applicationDirectoryassetsrN/AN/AYes
/data/data/<app-id>/applicationStorageDirectory-r/wN/AN/AYes
/data/data/<app-id>/cachecacheDirectorycacheCACHEcontext.getCacheDir()r/wYesYes*Yes
/data/data/<app-id>/filesdataDirectoryfilesDATA, LIBRARYcontext.getFilesDir()r/wYesNoYes
/data/data/<app-id>/files/Documentsdocumentsnew File(context.getFilesDir(), “Documents”)r/wYesNoYes
<sdcard>/externalRootDirectorysdcardEXTERNAL_STORAGEYesGenerally no access. Only acess files the app createdEnvironment.getExternalStorageDirectory()r/wYesNoNo
<sdcard>/Android/data/<app-id>/externalApplicationStorageDirectory-context.getExternalFilesDir(null).getParentFile()r/wYesNoNo
<sdcard>/Android/data/<app-id>/cacheexternalCacheDirectorycache-externalcontext.getExternalCacheDir()r/wYesNo**No
<sdcard>/Android/data/<app-id>/files/externalDataDirectoryfiles-externalEXTERNALcontext.getExternalFilesDir(null)r/wYesNoNo
<sdcard>/DocumentsDOCUMENTSYesGenerally no access. Only access files the app createdEnvironment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)

iOS Conversion

Device Pathcordova.file.*iosExtraFileSystemsCapacitorFileManager.SearchPathDirectoryr/w?persistent?OS clearssyncprivate
/var/mobile/Applications/<uuid>/applicationStorageDirectory-rN/AN/AN/AYes
/var/mobile/Applications/<uuid>/appname.app/applicationDirectorybundlerN/AN/AN/AYes
/var/mobile/Applications/<uuid>/appname.app/www/--rN/AN/AN/AYes
/var/mobile/Applications/<uuid>/Documents/documentsDirectorydocumentsDOCUMENTS, DATA, EXTERNAL, EXTERNAL_STORAGE.documentDirectoryr/wYesNoYesYes
/var/mobile/Applications/<uuid>/Documents/NoCloud/-documents-nosyncr/wYesNoNoYes
/var/mobile/Applications/<uuid>/Library/-libraryLIBRARY.libraryDirectoryr/wYesNoYes?Yes
/var/mobile/Applications/<uuid>/Library/NoCloud/dataDirectorylibrary-nosyncr/wYesNoNoYes
/var/mobile/Applications/<uuid>/Library/Cloud/syncedDataDirectory-r/wYesNoYesYes
/var/mobile/Applications/<uuid>/Library/Caches/cacheDirectorycacheCACHE.cachesDirectoryr/wYes*Yes***NoYes
/var/mobile/Applications/<uuid>/tmp/tempDirectory-r/wNo**Yes***NoYes

Sources:

  • https://capacitorjs.com/docs/apis/filesystem#enums
  • https://cordova.apache.org/docs/en/11.x/reference/cordova-plugin-file/