2

I have an app in a capacitor where I want to convert base64 to File object.
I am using code from this answer,
this works fine on the web but when I try to run in the actual android app it is returning a strange file object.
Data from bytes array shows in name instead of actual name, and name shows in localURL.

new File(['bytes'], 'test.png')

This works fine in web, but when I run it as native app
Result of this in web

File {name: "test.png", lastModified: 1623044932737....

Result of this in app

File {name: ['bytes'], lastModified: 1623044932737....

I tried switching parameters as well but still no luck.

5
  • It would appear you may have your constructor params backward. new File(array, filename) seems to be what it's looking at based on your screenshot, but yet the name and local URL props are showing the opposite of what you want them to. This leads me to think your params are backward. Commented Jun 6, 2021 at 16:52
  • Also, check this page from the android docs about the File object: developer.android.com/reference/java/io/File Commented Jun 6, 2021 at 16:54
  • I tried params backward as well but no luck with that either. Commented Jun 6, 2021 at 17:37
  • Please don't post images of code or errors. See How to Ask. Commented Jun 6, 2021 at 18:51
  • @DivyeshSavaliya can you post the snippet of code where you're creating this file? Would help immensely Commented Jun 6, 2021 at 19:43

1 Answer 1

0

The problem was when i run app on native device,
it has cordova-plugin-file installed and its definition is
var File = function (name, localURL, type, lastModifiedDate, size) {

Which is overriding the existing javascript file function.

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

1 Comment

How did you assign the data to the file then?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.