11

I'm using Expo and try to download files using react-native-fetch-blob

import RNFetchBlob from 'rn-fetch-blob';

RNFetchBlob.fetch('GET', 'http://www.example.com/images/img1.png')
  .then((res) => {
    let status = res.info().status;
  })
  .catch((errorMessage, statusCode) => {
  })

There is an error occurs: null is not an object (evaluating 'RNFetchBlob.DocumentDir')

What i've already tried:

npm install --save react-native-fetch-blob
react-native link 
npm install --save react-native-fetch-blob
react-native link react-native-fetch-blob
var RNFetchBlob = require('rn-fetch-blob').default
RNFB_ANDROID_PERMISSIONS=true react-native link

I cannot do manually linking, because i use expo and do not have /ios and /android folders.

Could anyone help, how to fix this issue? Is rn-fetch-blob work with Expo?

Hardik Virani
  • 1,687
  • 7
  • 23
  • 36

4 Answers4

12

rn-fetch-blob doesn't work with expo.

rn-fetch-blob implements native code, and so it cannot be used in expo based projects. You would need to eject from expo

Does rn-fetch-blob work with Expo?

0

add another .then before u use the result. Like this: const result= res.json()

If you need to see status, directly use res.status

Howard Wu
  • 57
  • 4
  • 1
    it didn't help unfortunately. Even if i not use any RNFetchBlob function, only one string ```import RNFetchBlob from 'rn-fetch-blob'``` causes this error –  Jan 11 '20 at 18:18
0

Change the directory to: ios and run: pod install if you have run the app from XCode on real device, re-run it again.

Adriatik Gashi
  • 332
  • 4
  • 10
0

For react native after change import RNFetchBlob from 'rn-fetch-blob' to import { RNFetchBlob } from 'rn-fetch-blob'; in the node modules the error goes away.