1

I have tried to research for the right answer for me on saving captured images or videos to custom folder on device but have not seen a suitable answers. I have been able to save to my DCIM, but I don't want to save them there, I want to create a custom folder to save my captured images or video from my app. I am new to react native and this is my learning process...

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 });
Benjamin Ikwuagwu
  • 377
  • 1
  • 9
  • 28

1 Answers1

0

You have to use the album parameter of CameraRoll.save

CameraRoll.save(data.uri, {type:'photo',album:'CustomFolder'});

from the docs

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.

Guruparan Giritharan
  • 15,660
  • 4
  • 27
  • 50
  • It still saving to DCIM, and not saving to CustomFolder – Benjamin Ikwuagwu Jul 01 '20 at 04:44
  • can you try CameraRoll.save(data.uri, {type:'photo',album:'CustomFolder'}); ? – Guruparan Giritharan Jul 01 '20 at 05:02
  • Oh yeah...super excited it worked, thanks Guruparan. I don't know if I should create a new question or I should still ask the question here...there's still a lot I want to achieve with my test app...I want to retrieve the images into my app as gallery with thumbnails: I want to be able to share and delete picture...please I still need help here. Thanks. – Benjamin Ikwuagwu Jul 01 '20 at 08:29
  • i've updated the answer, hope you can mark it, as its a whole different thing better if you create a new question :) – Guruparan Giritharan Jul 01 '20 at 08:31