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

▼魔方 西西 提交于 2020-07-18 08:49:04

问题


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.


回答1:


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




回答2:


I was getting this error because my URL was incorrect




回答3:


This will resolve the issue : alert(JSON.stringify(data))




回答4:


In my case I was not running the api server.




回答5:


I also faced the same issue and the below line of code can be a solution.

var formdata = new FormData();
formdata.append("mobile", phonenumber);

var requestOptions = {
method: 'POST',
body: formdata,
redirect: 'follow'
};

fetch("http://your_url", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));



回答6:


react-native link

Use this command to resolve this issue. This worked for me.

Note : Only for react-native < 60.x



来源:https://stackoverflow.com/questions/50623080/com-facebook-react-bridge-readablenativemap-cannot-be-cast-to-java-lang-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!