我得到错误无法在'FileReader'上执行'readAsText':参数1不是'Blob'类型。我的库是0.10.8版本。我试图将 react native fetch blob 降级到 0.9.5,但我遇到了另一个错误。
未定义侦听器
我在 github 上读过问题,但我不太了解他们的解决方案,我现在很困惑。
const Blob = RNFetchBlob.polyfill.Blob
const fs = RNFetchBlob.fs
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
window.Blob = Blob
const screenWidth = Dimensions.get('window').width
const uploadImage = (uri, imageName, mime = 'image/jpg') => {
return new Promise((resolve, reject) => {
const uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri
let uploadBlob = null
const imageRef = firebaseApp.storage().ref('posts').child(imageName)
fs.readFile(uploadUri, 'base64')
.then((data) => {
return Blob.build(data, { type: `${mime};BASE64` })
})
.then((blob) => {
uploadBlob = blob
return imageRef.put(blob, { contentType: mime })
})
.then(() => {
uploadBlob.close()
return imageRef.getDownloadURL()
})
.then((url) => {
resolve(url)
})
.catch((error) => {
reject(error)
})
})
}