How to download an image with CRNA

If you are building app with Expo, to down load an image to Galary of mobile from a link image. You can use FileSystem from expo.

const fileUri = FileSystem.documentDirectory + fileName;
FileSystem.downloadAsync(
   imageUrl,
   fileUri
)
.then(({ uri }) => {
    console.log('Finished downloading to ', uri);
})
  • fileName: name of image, u can get name from imageUrl or any name
  • imageUrl: link url contains the image
  • fileUri: is uri contains the image after download

After download, will be returned an uri that save the image. You should check download successfully with getInfoAsync image, if return exists not equal 0.

To save the image into Galary of mobile, you should do this

import { CameraRoll } from "react-native"

FileSystem.getInfoAsync(uri)
  .then((res) => {
    console.log('res ', res)
    CameraRoll.saveToCameraRoll(uri, 'photo')
ca  })

Done. Open Galary on mobile to check


All Rights Reserved