How to download an image with CRNA
Bài đăng này đã không được cập nhật trong 6 năm
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 fromimageUrl
or any nameimageUrl
: link url contains the imagefileUri
: 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