# File.writeFile: Not working on Android Capacitor

**URL:** <https://forum.ionicframework.com/t/file-writefile-not-working-on-android-capacitor/223463>\
**Category:** Capacitor\
**Created:** [May 21, 2022, 7:45pm UTC](https://forum.ionicframework.com/t/file-writefile-not-working-on-android-capacitor/223463 "2022-05-21T19:45:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Malte94](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Malte94](https://forum.ionicframework.com/u/Malte94)\
**Post date:** [May 21, 2022, 7:45pm UTC](https://forum.ionicframework.com/t/file-writefile-not-working-on-android-capacitor/223463/1 "2022-05-21T19:45:12Z")

</div>

Heyo,

I am using the following code to download a file. This works on iOS without any issue.

On Android at least in the emulator on the localhost. However, after deploying to the server and running the app either in an emulator pointing to this, or a real device, an error message appears. Only on Android.

Do you have any idea how I can solve this? Thank you! 🙂

```auto
    if (isPlatform('android')) {
        try {
            setTimeout(() => {
                File.removeFile(File.externalDataDirectory, filename)
            }, 2000)
        } catch (e) {
            console.log(e)
        }
        File.writeFile(File.externalDataDirectory, filename, content, true).then(success => {
            FileOpener.showOpenWithDialog(File.externalDataDirectory + filename, mimeType)
                .then(() => console.log('File opened'))
                .catch(e => toast.error("Fehler beim Öffnen der Datei: " + e));
        })
            .catch(e => toast.error("Fehler beim Speichern der Datei: " + e));
    }

```

` Uncaught TypeError: Cannot read property 'then' of undefined`

---

<div class="post-metadata">

**Author:** ![Malte94](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Malte94](https://forum.ionicframework.com/u/Malte94)\
**Post date:** [May 22, 2022, 8:27am UTC](https://forum.ionicframework.com/t/file-writefile-not-working-on-android-capacitor/223463/2 "2022-05-22T08:27:36Z")

</div>

I gave it now a second attempt with the Capacitor’s implementation. Same issue.

```auto
    if (isPlatform('android')) {
        if (filename.includes(".json")) {
            filename = filename.replace(".json", ".xlsx");
            encodeBase64(content)
        }
        const result = await Filesystem.writeFile({
            path: filename,
            data: content,
            directory: Directory.Documents
        });

        FileOpener.showOpenWithDialog(result.uri, mimeType)
    }

```

---

<div class="post-metadata">

**Author:** ![Malte94](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Malte94](https://forum.ionicframework.com/u/Malte94)\
**Post date:** [May 22, 2022, 1:50pm UTC](https://forum.ionicframework.com/t/file-writefile-not-working-on-android-capacitor/223463/3 "2022-05-22T13:50:30Z")

</div>

I could resolve the issue. Android Capacitor does not seem to be supporting the service-worker. I removed it from React and the server. Plugins are working fine now.
