Question
Error: Unable to Write File to applicationDirectory in Capacitor Filesystem
Ash Lane
0 reputation · 13 Nov 2024, 10:40 UTC
126.1K views0
Problem: writeFile fails on applicationDirectory
When attempting to write a file to applicationDirectory using Capacitor’s Filesystem plugin, the operation throws a failure. The directory is intended to contain the app bundle’s assets and is read‑only after the app is installed on both iOS and Android.
Constraints & Considerations
- applicationDirectory is immutable post‑install; attempts to write return an error.
- Mutable storage must be placed in
documentsDirectory,libraryDirectory, orcacheDirectory. - Data in
documentsDirectoryis backed up to iCloud or device backups unless excluded. - Path strings differ between iOS and Android and can change across OS updates.
Unresolved Questions
- What is the precise error message returned when writing to
applicationDirectoryon iOS vs. Android? - Which directory constant should be used for data that must persist across app launches but should not be exposed in backups?
- How can developers explicitly prevent sensitive files from being included in iCloud or device backups on iOS?