I'm building an Ionic app with Capacitor, and I need to write a temporary file that I will be uploading to a webservice then deleting.
The Capacitor Filesystem API uses an object to specify the file to be written or read:
Filesystem.writeFile({
path: 'secrets/text.txt',
data: "This is a test",
directory: FilesystemDirectory.Documents,
encoding: FilesystemEncoding.UTF8
})
Capacitor does some cross-platform magic to combine the relative path and the FileSystemDirectory enumeration to create a file appropriate for the platform.
The FileSystemDirectory enumeration:
enum FilesystemDirectory {
// The Application directory
Application: "APPLICATION"
// The Cache directory
Cache: "CACHE"
// The Data directory
Data: "DATA"
// The Documents directory
Documents: "DOCUMENTS"
// The external directory (Android only)
External: "EXTERNAL"
// The external storage directory (Android only)
ExternalStorage: "EXTERNAL_STORAGE"
}
Which of these, Application, Cache, Data, or Documents would be most appropriate for a temporary file?
Use Cache folder for files that can be recreated as the OS can delete them in cases of low memory.