React Native 将捕获的图像和视频保存到我设备上的自定义文件夹
React Native Save captured images and video to custom folder on my device
我已尝试研究关于将捕获的图像或视频保存到设备上的自定义文件夹的正确答案,但没有找到合适的答案。我已经能够保存到我的 DCIM,但我不想将它们保存在那里,我想创建一个自定义文件夹来保存我从我的应用程序捕获的图像或视频。我是 React Native 的新手,这是我的学习过程...
takePicture = async () => {
if (this.camera) {
if (Platform.OS === 'android') {
await this.checkAndroidPermission();
}
const options = { quality: 1 };
const data = await this.camera.takePictureAsync(options);
//save photo
CameraRoll.save(data.uri, 'photo').then(onfulfilled => {
ToastAndroid.show(`VidApp Photos: ${onfulfilled}`, ToastAndroid.SHORT);
}).catch(error => {
ToastAndroid.show(`${error.message}`, ToastAndroid.SHORT);
});
}
};
recordVideo = async () => {
if (this.camera) {
if (!this.state.recording)
this.startRecording();
else this.stopRecording();
}
}
startRecording = async () => {
this.setState({ recording: true });
this.countRecordTime = setInterval(() => this.setState({ seconds: this.state.seconds + 1 }), 1000);
const cameraConfig = { maxDuration: this.state.maxDuration };
const data = await this.camera.recordAsync(cameraConfig);
this.setState({ recording: false });
CameraRoll.save(data.uri, 'video').then(onfulfilled => {
ToastAndroid.show(`VidApp Videos: ${onfulfilled}`, ToastAndroid.SHORT)
}).catch(error => ToastAndroid.show(`${error.message}`, ToastAndroid.SHORT));
}
stopRecording = () => {
this.camera.stopRecording();
clearInterval(this.countRecordTime);
this.setState({ seconds: 0 });
您必须使用 CameraRoll.save
的相册参数
CameraRoll.save(data.uri, {type:'photo',album:'CustomFolder'});
来自文档
It allows to specify a particular album you want to store the asset to
when the param album is provided. On Android, if no album is provided,
DCIM directory is used, otherwise PICTURE or MOVIES directory is used
depending on the type provided.
我已尝试研究关于将捕获的图像或视频保存到设备上的自定义文件夹的正确答案,但没有找到合适的答案。我已经能够保存到我的 DCIM,但我不想将它们保存在那里,我想创建一个自定义文件夹来保存我从我的应用程序捕获的图像或视频。我是 React Native 的新手,这是我的学习过程...
takePicture = async () => {
if (this.camera) {
if (Platform.OS === 'android') {
await this.checkAndroidPermission();
}
const options = { quality: 1 };
const data = await this.camera.takePictureAsync(options);
//save photo
CameraRoll.save(data.uri, 'photo').then(onfulfilled => {
ToastAndroid.show(`VidApp Photos: ${onfulfilled}`, ToastAndroid.SHORT);
}).catch(error => {
ToastAndroid.show(`${error.message}`, ToastAndroid.SHORT);
});
}
};
recordVideo = async () => {
if (this.camera) {
if (!this.state.recording)
this.startRecording();
else this.stopRecording();
}
}
startRecording = async () => {
this.setState({ recording: true });
this.countRecordTime = setInterval(() => this.setState({ seconds: this.state.seconds + 1 }), 1000);
const cameraConfig = { maxDuration: this.state.maxDuration };
const data = await this.camera.recordAsync(cameraConfig);
this.setState({ recording: false });
CameraRoll.save(data.uri, 'video').then(onfulfilled => {
ToastAndroid.show(`VidApp Videos: ${onfulfilled}`, ToastAndroid.SHORT)
}).catch(error => ToastAndroid.show(`${error.message}`, ToastAndroid.SHORT));
}
stopRecording = () => {
this.camera.stopRecording();
clearInterval(this.countRecordTime);
this.setState({ seconds: 0 });
您必须使用 CameraRoll.save
的相册参数CameraRoll.save(data.uri, {type:'photo',album:'CustomFolder'});
来自文档
It allows to specify a particular album you want to store the asset to when the param album is provided. On Android, if no album is provided, DCIM directory is used, otherwise PICTURE or MOVIES directory is used depending on the type provided.