com.facebook.react.bridge.readablenativemap cannot be cast to java.lang.string

kutirie picture kutirie · May 31, 2018 · Viewed 32.6k times · Source

My code:

const file = {
  uri: this.state.imageSource,
  name: this.state.imageName,
  type: 'image/jpg',
};

const data = new FormData();
data.append('file', file);

fetch(config.server + '/upload', {
  method: 'POST',
  body: data,
})
  .then((res) => res.json())
  .then((responseData) => {
    alert(JSON.stringify(responseData));
  })
  .catch((err) => {
    alert(err);
  });

Without FormData code doesnt display error. What I should do to fix? Debugging on android.

Answer

kutirie picture kutirie · Jun 25, 2018

The error was because I was passing in the url as an array but it expected a string.