I am using react native cameraroll api to save my images in storage.
CameraRoll.saveToCameraRoll(data.uri)
.then(console.log('Success', 'Photo added to camera roll!'))
.catch(err => console.log('err:', err))
Above code successfully save image in storage like (DCIM/imageName.jpg)
But i want to change the location of images to be saved somewhere else like (testfolder/1/imagename.jpg) I tried like this:
CameraRoll.saveToCameraRoll({
uri: data.uri,
album: 'test',
}, 'photo').then((newUri) => {
console.log('new location of image => ', newUri);
})
I read this link .html#savetocameraroll but there is no proper guide or parameter set to change location.
Anyone guide me how can i change path for saving images?
I am using react native cameraroll api to save my images in storage.
CameraRoll.saveToCameraRoll(data.uri)
.then(console.log('Success', 'Photo added to camera roll!'))
.catch(err => console.log('err:', err))
Above code successfully save image in storage like (DCIM/imageName.jpg)
But i want to change the location of images to be saved somewhere else like (testfolder/1/imagename.jpg) I tried like this:
CameraRoll.saveToCameraRoll({
uri: data.uri,
album: 'test',
}, 'photo').then((newUri) => {
console.log('new location of image => ', newUri);
})
I read this link https://facebook.github.io/react-native/docs/cameraroll.html#savetocameraroll but there is no proper guide or parameter set to change location.
Anyone guide me how can i change path for saving images?
Share Improve this question asked Mar 30, 2018 at 5:48 DIGITAL JEDIDIGITAL JEDI 1,6663 gold badges29 silver badges54 bronze badges 2- 5 anybody have solution for this? – DIGITAL JEDI Commented Mar 30, 2018 at 8:59
- 2 DIGITAL JEDI, got any answers? If yes, please share. – Vikas Gupta Commented Feb 8, 2019 at 5:37
2 Answers
Reset to default 2As I said here : How to save a Picture to a specific folder from React Native Camera Roll
On Android, you can use react-native-fetch-blob and its File System Access API (PictureDir constant).
try {
const data = await this.camera.takePictureAsync()
await RNFetchBlob.fs.mkdir(`${RNFetchBlob.fs.dirs.PictureDir}/myfolder`)
await RNFetchBlob.fs.mv(
data.api,
`${RNFetchBlob.fs.dirs.PictureDir}/myfolder/${moment().unix()}.jpg`
)
} catch () {
...
}
https://github./wkh237/react-native-fetch-blob/wiki/File-System-Access-API
I know that I am too late for this answer. But I got solutions without using rn-fetch-blob library.
You can simply use below npm package for get your desired output
npm i @react-native-munity/cameraroll
and after that you have to use below code in try catch block so you can easily store your image on your desired path.
try{
CameraRoll.save(data.uri,{type:"photo",album:"../your folder name"}).
then((res)=>{console.log("save img...",res);}).
catch((err)=>{console.log("err for save img...",err);})
}
catch{
//your code...
}