Skip to content

@capgo/capacitor-file

Capacitor File Plugin Implements file system operations similar to the Cordova File plugin.

Capacitor File Plugin Implements file system operations similar to the Cordova File plugin.

  • requestFileSystem - Request a file system.
  • resolveLocalFileSystemURL - Resolve a file URL to an entry.
  • getFile - Get a file entry.
  • getDirectory - Get a directory entry.
MethodDescription
requestFileSystemRequest a file system.
resolveLocalFileSystemURLResolve a file URL to an entry.
getFileGet a file entry.
getDirectoryGet a directory entry.
readFileRead a file as text or base64.
readAsDataURLRead a file as a data URL (base64 with MIME type prefix).
writeFileWrite data to a file.
appendFileAppend data to a file.
deleteFileDelete a file.
mkdirCreate a directory.
rmdirDelete a directory.
readdirRead directory contents.
statGet metadata about a file or directory.
getMetadataGet metadata about a file or directory. Alias for stat().
renameRename or move a file or directory.
moveMove a file or directory. Alias for rename().
copyCopy a file or directory.
existsCheck if a file or directory exists.
getUriGet the URI for a file.
truncateTruncate a file to a specified size.
getDirectoriesGet all known file system directories.
getFreeDiskSpaceGet the free disk space in bytes.
addListenerListen for read progress events.
addListenerListen for write progress events.
removeAllListenersRemove all event listeners.
getPluginVersionGet the plugin version.
checkPermissionsCheck the current permission status for file operations. On Android, this checks for external storage permissions. On iOS and web, this always returns ‘granted’ as no special permissions are needed.
requestPermissionsRequest permissions for file operations. On Android, this requests external storage permissions needed for accessing files outside the app’s private directories. On iOS and web, this always returns ‘granted’ as no special permissions are needed.

Use these values when choosing a storage location, writing encoded text, or handling file errors.

ValueUser will find
DOCUMENTSPersistent user-visible documents. On Android this maps to the app files directory.
DATAPersistent private app data.
LIBRARYPersistent app data that is not user-visible. On Android this maps to the app files directory.
CACHETemporary cache data that the OS may clear.
EXTERNALAndroid external storage root, such as an SD card or shared external storage.
EXTERNAL_STORAGEAndroid external storage data directory.
APPLICATIONRead-only application bundle or assets directory.
ValueUse
utf8UTF-8 text.
asciiASCII text.
utf16UTF-16 text.
ValueCodeMeaning
NOT_FOUND_ERR1File or directory was not found.
SECURITY_ERR2Operation was blocked by security rules or permissions.
ABORT_ERR3Operation was aborted.
NOT_READABLE_ERR4File or directory cannot be read.
ENCODING_ERR5Encoding is invalid or unsupported.
NO_MODIFICATION_ALLOWED_ERR6Target cannot be modified.
INVALID_STATE_ERR7Object is in an invalid state for the operation.
SYNTAX_ERR8Path or input syntax is invalid.
INVALID_MODIFICATION_ERR9Requested change is invalid for the target.
QUOTA_EXCEEDED_ERR10Storage quota was exceeded.
TYPE_MISMATCH_ERR11Value type does not match the expected type.
PATH_EXISTS_ERR12Target path already exists.

This reference is synced from src/definitions.ts in capacitor-file.

If you are using @capgo/capacitor-file to plan storage and file handling, connect it with Using @capgo/capacitor-file for the native capability in Using @capgo/capacitor-file, @capgo/capacitor-data-storage-sqlite for the implementation detail in @capgo/capacitor-data-storage-sqlite, Using @capgo/capacitor-data-storage-sqlite for the native capability in Using @capgo/capacitor-data-storage-sqlite, @capgo/capacitor-uploader for the implementation detail in @capgo/capacitor-uploader, and Using @capgo/capacitor-uploader for the native capability in Using @capgo/capacitor-uploader.