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)
)
did it get resolved ?
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)
)
i have the same error in Uploading image.
i tried your ways but does not work
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?
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
)
Most helpful comment
in my case, there was needed to stringify body