本文介绍了如何将图片从 React Native 相机胶卷保存到特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
So I'm using Expo's Camera API to take a picture, like so:
takePicture = async function() {
if(this.camera) {
this.camera.takePictureAsync().then(data => {
CameraRoll.saveToCameraRoll(data.uri);
}).then(() => {
this.setState({
photoId: this.state.photoId + 1,
});
});
}
};
Now, I'd like to specifically retrieve the pictures I take with this app to work with later. I figure an easy way to do this would be if the app saved its pictures to a separate folder in the camera roll, much like how Instagram makes its own folder in there.
How would I go about having the app create its own folder in the camera roll, and then saving pictures to it?
解决方案
On Android, you can use react-native-fetch-blob and its File System Access API (PictureDir constant).
For example, I do:
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 相机胶卷保存到特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!