# Does Capacitor writeFIle only write strings to txt files?

**URL:** <https://forum.ionicframework.com/t/does-capacitor-writefile-only-write-strings-to-txt-files/158683>\
**Category:** Ionic Native\
**Created:** [March 10, 2019, 6:28am UTC](https://forum.ionicframework.com/t/does-capacitor-writefile-only-write-strings-to-txt-files/158683 "2019-03-10T06:28:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wekas](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/wekas/32/124745_2.png) [@wekas](https://forum.ionicframework.com/u/wekas)\
**Post date:** [March 10, 2019, 6:28am UTC](https://forum.ionicframework.com/t/does-capacitor-writefile-only-write-strings-to-txt-files/158683/1 "2019-03-10T06:28:03Z")

</div>

I am trying to write a pdf to file on an android device with data either as blob or base64 but the Capacitor writeFile only seems to accept a string as data and creates a text document.  
When I gave it a base64 string it just dumped it into the file as text.

**Is there any way to write a file using blob or base64 or will I have to give up and convert my project back to Cordova?**

[https://capacitor.ionicframework.com/docs/apis/filesystem](https://capacitor.ionicframework.com/docs/apis/filesystem)

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [March 10, 2019, 6:48am UTC](https://forum.ionicframework.com/t/does-capacitor-writefile-only-write-strings-to-txt-files/158683/2 "2019-03-10T06:48:42Z")

</div>

Linked with: [https://forum.ionicframework.com/t/capacitor-writefile-saving-pdf-file-is-in-invalid-format](https://forum.ionicframework.com/t/capacitor-writefile-saving-pdf-file-is-in-invalid-format)

---

<div class="post-metadata">

**Author:** ![wekas](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/wekas/32/124745_2.png) [@wekas](https://forum.ionicframework.com/u/wekas)\
**Post date:** [March 10, 2019, 7:25am UTC](https://forum.ionicframework.com/t/does-capacitor-writefile-only-write-strings-to-txt-files/158683/3 "2019-03-10T07:25:40Z")

</div>

Solved:  
Remove the encoding parameter.  
See:

> [@Capacitor writeFile - Saving pdf file is in invalid format](https://forum.ionicframework.com/t/capacitor-writefile-saving-pdf-file-is-in-invalid-format/158633/13):
>
> You sir are a genius! I would buy you a beer if you were in my timezone wink Great idea to look at the code. I got it working. I just needed to remove the UTF8 encoding. So… If you look at the docs here ([https://capacitor.ionicframework.com/docs/apis/filesystem/#type-401](https://capacitor.ionicframework.com/docs/apis/filesystem/#type-401)) It says that the encoding defaults to UTF8, so I didn’t think removing it would make any difference. However looking at the code in the link you sent it defaults to plain text if you provide a value in encoding. Char…
