joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 773 forks source link

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

Open Bradzer opened 4 years ago

Bradzer commented 4 years ago

Why do I get the error with my code :

            RNFetchBlob.config({fileCache: true}).fetch("https://gateway-lon.watsonplatform.net/text-to-speech/api/v1/synthesize?accept=audio%2Fwav&text=hola%20mundo&voice=es-ES_EnriqueVoice",
            {
                method: 'GET',
                headers: {
                    'Authorization': 'Basic ' + btoa('apikey:my_api_key_here'),
                }
            })
            .then(
            (res) =>  console.log('response has arrived'),
            (error) => console.log('ERROR OCCURED', error)
            )
Anu1612 commented 4 years ago

did it get resolved ?

Bradzer commented 4 years ago

I figured it was a syntax error

The fetch method is supposed to take 3 parameters : the http method ('GET', 'POST', etc...), the url to fetch and the headers.

The right syntax is :

            RNFetchBlob.config({fileCache: true}).fetch('GET', "https://gateway-lon.watsonplatform.net/text-to-speech/api/v1/synthesize?accept=audio%2Fmp3&text=hola%20mundo&voice=es-ES_EnriqueVoice",
            {
                Authorization: 'Basic ' + btoa('apikey:my_api_key_here')
            })
            .then(
            (res) => console.log('response has arrived'),
            (error) => reactotron.log('ERROR OCCURED', error)
            )
myomyintaung1411 commented 4 years ago

i have the same error in Uploading image. i tried your ways but does not work

vitto-moz commented 4 years ago

according to types, there are 4 parameters


interface RNFetchBlobStatic {
    fetch(method: Methods, url: string, headers?: { [key: string]: string }, body?: any
        | null): StatefulPromise<FetchBlobResponse>;

what about body?

vitto-moz commented 4 years ago

in my case, there was needed to stringify body

RNFetchBlob.fetch(
      config.method || DEFAULT_CONFIG.method,
      config.url,
      {Authorization: token, ...DEFAULT_CONFIG.headers},
      JSON.stringify(config.body) // <==== here
    )
hungdev commented 3 years ago

in my case, there was needed to stringify body

RNFetchBlob.fetch(
      config.method || DEFAULT_CONFIG.method,
      config.url,
      {Authorization: token, ...DEFAULT_CONFIG.headers},
      JSON.stringify(config.body) // <==== here
    )

Thank you so much!. It worked <3