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.

Divyesh Savaliya
  • 2,692
  • 2
  • 18
  • 37
  • 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. – Kwright02 Jun 06 '21 at 16:52
  • Also, check this page from the android docs about the File object: https://developer.android.com/reference/java/io/File – Kwright02 Jun 06 '21 at 16:54
  • I tried params backward as well but no luck with that either. – Divyesh Savaliya Jun 06 '21 at 17:37
  • Please don't post images of code or errors. See [ask]. – Robert Jun 06 '21 at 18:51
  • @DivyeshSavaliya can you post the snippet of code where you're creating this file? Would help immensely – Kwright02 Jun 06 '21 at 19:43

1 Answers1

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.

Divyesh Savaliya
  • 2,692
  • 2
  • 18
  • 37