0

I have created a simple app which captured the image and upload to the AWSs3. I want to store those image in my app folder. (I have created this once my app installed). I want to store captured images to that folder instead of the Pictures folder. I am using react-native-image-picker to capture the image.

My code is,

import ImagePicker from 'react-native-image-picker';
import RNFS from 'react-native-fs';
takePic = () => {

    const options = {
      quality: 1.0,
      maxWidth: 100,
      maxHeight: 100,
      base64: true,
      skipProcessing: true
  }
  const pictureFolder = RNFetchBlob.fs.dirs.SDCardDir+'/Pictures/Text/';
    ImagePicker.launchCamera(options,(responce)=>{

        this.state.testImage.push({ uri: responce.uri });
          const file ={
            uri   : responce.uri,
            name :DeviceInfo.getUniqueID()+'_'+this.props.longitude+'_'+this.props.latitude+'_'+this.state.capturedTime+'_'+this.state.schoolId+'_'+this.state.userId+'_'+this.state.SelectedClass+'_'+this.state.SelectedSection+'_'+this.state.SelectedSubject+'.jpg',
            method: 'POST',
            //path : pictureFolder+responce.fileName,
            path : responce.path,
            type :  responce.type,
            notification: {
                enabled: true
              }
          }

          console.log(pictureFolder);
      });

(I have updated only part of the code). I tried to mention the destination directory externally using react-native-fs. But I did not.

Can anyone assist me to do so?

Vidya Kabber
  • 171
  • 1
  • 16

1 Answers1

0

Assuming that a folder is already there is the gallery folder

  • Try this:

    const APP_FOLDER_NAME = 'MyApp';
      const pictureFolder = `${RNFS.PicturesDirectoryPath}/${APP_FOLDER_NAME}`;
      ImagePicker.launchCamera(options, (response) => {
        const { uri } = response;
        const fileName = new Date().getTime();
        RNFS.copyFile(uri, `${pictureFolder}/${fileName}`)
        .then(() => RNFS.scanFile(`${albumPath}/${fileName}`));
      });
    

This step is very important to see the file in your folder without restarting your emulator, or device:

.then(() => RNFS.scanFile(`${albumPath}/${fileName}`));
Hend El-Sahli
  • 6,268
  • 2
  • 25
  • 42
  • Thank you, sir :). Instead of copyFile, I have used moveFile and some changes I have done according to my requirements. It is working fine. – Vidya Kabber Mar 18 '19 at 10:50