1
我使用的是npm包react-native-fetch-blob。
我已遵循git repository的所有步骤来使用该软件包。npm react-native-fetch-blob - “RNFetchBlob.fetch不是函数”
我然后导入使用以下行软件包:
var RNFetchBlob = require('react-native-fetch-blob');
我试图请求来自服务器包含图像的BLOB。
这是我的主要方法。
fetchAttachment: function(attachment_uri) {
var authToken = 'youWillNeverGetThis!'
var deviceId = '123';
var xAuthToken = deviceId+'#'+authToken
//Authorization : 'Bearer access-token...',
// send http request in a new thread (using native code)
RNFetchBlob.fetch('GET', config.apiRoot+'/app/'+attachment_uri, {
'Origin': 'http://10.0.1.23:8081',
'X-AuthToken': xAuthToken
})
// when response status code is 200
.then((res) => {
// the conversion is done in native code
let base64Str = res.base64()
// the following conversions are done in js, it's SYNC
let text = res.text()
let json = res.json()
})
// Status code is not 200
.catch((errorMessage, statusCode) => {
// error handling
});
}
我不断收到以下错误:
“可能未处理无极便餐(ID:0):类型错误:RNFetchBlob.fetch不是一个函数”。
有什么建议吗?
尝试VAR RNFetchBlob =需要( '反应原生取-斑点')违约; – rmevans9
@Cherniv根据[手册](https://www.npmjs.com/package/react-native-fetch-blob#recipes),它应该是'从...导入RNFetchBlob'。这就是为什么'.default'可能是必需的。 – robertklep
@ rmevans9工作。把它写成答案,我会接受解决方案。谢谢。 – Larney