npm react-native-fetch-blob-"RNFetchBlob.fetch不是函数". [英] npm react-native-fetch-blob - "RNFetchBlob.fetch is not a function"
本文介绍了npm react-native-fetch-blob-"RNFetchBlob.fetch不是函数".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用npm软件包 react-native-fetch-blob .
我已经按照 git存储库中的所有步骤进行操作,以使用该程序包.
I am using the npm package react-native-fetch-blob.
I have followed all the steps from the git repository to use the package.
然后我使用以下行导入软件包:
I then imported the package using the following line:
var RNFetchBlob = require('react-native-fetch-blob');
我正在尝试从服务器请求包含图像的BLOB.
I am trying to request a BLOB containing an image from the a server.
这是我的主要方法.
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):TypeError:RNFetchBlob.fetch不是函数".
有什么想法吗?
推荐答案
问题是您正在使用ES5样式的require语句以及针对ES6/ES2015编写的库.您有两种选择:
The issue is you are using ES5 style require statements with a library written against ES6/ES2015. You have two options:
ES5:
var RNFetchBlob = require('react-native-fetch-blob').default
ES6:
import RNFetchBlob from 'react-native-fetch-blob'
这篇关于npm react-native-fetch-blob-"RNFetchBlob.fetch不是函数".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文