Ionic Save large file @Capacitor/filesystem - Out of memory error

I try to store multiple files in the file storage by using the @Capacitor/filesystem Plugin.

On large files I’m facing the following error - testet on my One Plus Pro 8 (Android 12):

W/System.err: java.lang.OutOfMemoryError: Failed to allocate a 150994952 byte allocation with 25165824 free bytes and 140MB until OOM, target footprint 280973616, growth limit 402653184

Code for saving the files:

        data: file.base64,
        directory: Directory.Data,
        recursive: true

Project configuration:


   Ionic CLI                     : 6.19.0 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 6.0.8
   @angular-devkit/build-angular : 13.0.4
   @angular-devkit/schematics    : 13.0.4
   @angular/cli                  : 13.0.4
   @ionic/angular-toolkit        : 5.0.3


   Capacitor CLI      : 3.4.1
   @capacitor/android : 3.4.1
   @capacitor/core    : 3.4.1
   @capacitor/ios     : not installed


   cordova-res : not installed globally
   native-run  : 1.5.0

How large is the file? You may need to write a custom plugin if it is too large. That error is thrown when the Android application runs out of memory.

I encountered a similar issue where I had to save large files in chunks. While I could manage it using the Filesystem, albeit slowly, I also needed to read huge files shared with my app. So, I developed a plugin that can effectively handle large files. It’s inspired by the capacitor-blob-writer, but offers the ability to read and write files in chunks. Additionally, it supports encryption for enhanced security. I’d recommend giving it a try, as it might just be the solution you’re looking for.

1 Like