如何从React Native Camera Roll将图片保存到特定文件夹 [英] How to save a Picture to a specific folder from React Native Camera Roll
问题描述
因此,我正在使用Expo的Camera API拍照,如下所示:
takePicture = async function() {
if(this.camera) {
this.camera.takePictureAsync().then(data => {
CameraRoll.saveToCameraRoll(data.uri);
}).then(() => {
this.setState({
photoId: this.state.photoId + 1,
});
});
}
};
现在,我想专门检索我使用此应用拍摄的照片,以便以后使用.我想一种简单的方法是,将应用程序的图片保存到相机胶卷中的单独文件夹中,就像Instagram在其中创建自己的文件夹一样.
我将如何让该应用在相机胶卷中创建自己的文件夹,然后将图片保存到其中?
在Android 上,您可以使用react-native-fetch-blob及其文件系统访问API(PictureDir常量).>
例如,我这样做:
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
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 Camera Roll将图片保存到特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!