react-nativefetchmultipartform-data

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


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.


Solution

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