javascript - React Native save image to specific location - Stack Overflow

I am using react native cameraroll api to save my images in storage.CameraRoll.saveToCameraRoll(data.ur

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
Add a ment  | 

2 Answers 2

Reset to default 2

As 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...
    }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744795733a4594192.html

相关推荐

  • javascript - React Native save image to specific location - Stack Overflow

    I am using react native cameraroll api to save my images in storage.CameraRoll.saveToCameraRoll(data.ur

    2天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信