Image is not showing in the iOS device after getting downloaded through rn-fetch-blob ( React native fetch blob)

前端 未结 2 1931
我在风中等你
我在风中等你 2021-01-29 09:30

I am trying to download a small image using this particular code snippet :

Plug in Used : \"rn-fetch-blob\": \"^0.10.14\"

相关标签:
2条回答
  • 2021-01-29 10:00

    On iOS both documents and cache directory are contained within the application's own directory. So you are not storing the image in the device photos.

    To download it to the device photos you need to use CameraRoll from react-native https://facebook.github.io/react-native/docs/cameraroll

    import { CameraRoll } from 'react-native';
    

    This tutorial shows you how to use CameraRoll

    https://medium.com/react-native-training/mastering-the-camera-roll-in-react-native-13b3b1963a2d

    However the crux of it is you can use something like this to download images to the camera roll

    saveToCameraRoll = (image) => {
      if (Platform.OS === 'android') {
        RNFetchBlob
          .config({
            fileCache : true,
            appendExt : 'jpg'
          })
          .fetch('GET', image.urls.small)
          .then((res) => {
            CameraRoll.saveToCameraRoll(res.path())
              .then(Alert.alert('Success', 'Photo added to camera roll!'))
              .catch(err => console.log('err:', err))
          })
      } else {
          CameraRoll.saveToCameraRoll(image.urls.small)
            .then(Alert.alert('Success', 'Photo added to camera roll!'))
      }
    }
    
    0 讨论(0)
  • 2021-01-29 10:00

    What you wanted to do is to write base64 encoded image to a file but what you're writing is the image url only.

    0 讨论(0)
提交回复
热议问题