react-native-blob-util: Cannot read property 'rnfbEncode' of undefined, js engine: hermes
My code
import {Platform} from 'react-native'
import ReactNativeBlobUtil, {ReactNativeBlobUtilConfig} from 'react-native-blob-util'
export const options = (name: string, extension = 'pdf', notification = true) => {
const {fs} = ReactNativeBlobUtil
const {
dirs: {DocumentDir, DownloadDir},
} = fs
return Platform.select({
ios: {
fileCache: true,
path: `${DocumentDir}/${name}`,
title: name,
},
android: {
fileCache: true,
addAndroidDownloads: {
useDownloadManager: true,
notification,
title: name,
path: `${DownloadDir}/${name}.${extension}`,
},
},
}) as ReactNativeBlobUtilConfig
}
import {useCallback, useState} from 'react'
import {Platform} from 'react-native'
import ReactNativeBlobUtil from 'react-native-blob-util'
import {options} from '@/utils/blob'
import {filesPermission} from '@/utils/hardwarePermissions'
export const useFetchBlob = () => {
const [progress, setProgress] = useState<number>()
const fetchBlob = useCallback(
async (
url: string,
name: string,
extension?: string,
headers?: {
[key: string]: string
},
) => {
try {
const hasDownloadPermission = await filesPermission()
if (hasDownloadPermission) {
const {config} = ReactNativeBlobUtil
const res = await config(options(name, extension))
.fetch('GET', url, headers)
.progress((received, total) => {
setProgress(received / total)
})
if (Platform.OS === 'ios') {
ReactNativeBlobUtil.ios.previewDocument(res.path())
}
} else {
}
} catch (error) {} finally {
setProgress(undefined)
}
},
[progress],
)
return {
progress,
fetchBlob,
}
}
“react-native”: “0.72.7” “react-native-blob-util”: “^0.19.6”,
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 9
- Comments: 20 (3 by maintainers)
Commits related to this issue
- fixes #321 hopefully fixes this issue — committed to RonRadtke/react-native-blob-util by deleted user 3 years ago
Hi @mMarcos208 I think the issue is with package version, I also stumbled on the same error. So, I downgraded the version to
react-native-blob-util@0.19.4it works for me. Hope it helps.Comment the two line(273, 274) in fetch.js
Hi @mMarcos208, I have fixed this issue by wrapping the path with path: ReactNativeBlobUtil.wrap(filePath)
` import {Platform} from ‘react-native’ import ReactNativeBlobUtil, {ReactNativeBlobUtilConfig} from ‘react-native-blob-util’
export const options = (name: string, extension = ‘pdf’, notification = true) => { const {fs} = ReactNativeBlobUtil const { dirs: {DocumentDir, DownloadDir}, } = fs return Platform.select({ ios: { fileCache: true, path: ReactNativeBlobUtil.wrap(
${DocumentDir}/${name}), title: name, }, android: { fileCache: true, addAndroidDownloads: { useDownloadManager: true, notification, title: name, path: ReactNativeBlobUtil.wrap(${DownloadDir}/${name}.${extension}), }, }, }) as ReactNativeBlobUtilConfig } `Downgrade to 0.19.4 cause this error https://github.com/RonRadtke/react-native-blob-util/issues/204
It work for me.