问题描述
我正在使用 react native cameraroll api 将我的图像保存在存储中.
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))
以上代码成功将图像保存在存储中,如 (DCIM/imageName.jpg)
Above code successfully save image in storage like (DCIM/imageName.jpg)
但是我想更改要保存在其他地方的图像的位置,例如 (testfolder/1/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);
})
我阅读了这个链接 https://facebook.github.io/react-native/docs/cameraroll.html#savetocameraroll 但没有适当的指南或参数集来更改位置.
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?
推荐答案
正如我在这里所说的:如何将图片从 React Native Camera Roll 保存到特定文件夹
在 Android 上,您可以使用 react-native-fetch-blob 及其文件系统访问 API(PictureDir 常量).
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.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API
这篇关于React Native 将图像保存到特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!