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

Time:05-12

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:

Filesystem.writeFile({
        path,
        data: file.base64,
        directory: Directory.Data,
        recursive: true
      })

Project configuration:

**Ionic**:

   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**:

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

**Utility**:

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

CodePudding user response:

Saving large files is currently not supported (see https://github.com/ionic-team/capacitor/issues/984).

The Capacitor team has communicated on Discord that there are plans to add support with Capacitor 4.

CodePudding user response:

I found the following package wich solved my problem:

Capacitor-blob-writer

It splits the file into multiple parts if it's to low.

  • Related