1

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

2 Answers 2

1

I found the following package wich solved my problem:

Capacitor-blob-writer

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

The last comment in your posted issue refers only to files safed as Blobs. I convert all my files to a base64 string. So that shouldn't be the problem!
You can't transmit infinitely large strings. At some point, as in your case, there will be an OOM. Then the data must be transferred optimized (in smaller parts). However, such an interface does not yet exist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.