1

I am trying to develop an android application using react-native. and one of the requirement is to automatically save the capture image based on pre-defined filename programmatically. I am using react-native-image-picker.

The API of image-picker does not show way to save the image with per-defined filename programmatically. The tutorial I am using, does not show either.

Thanks a lot.

Andy Parinas
  • 71
  • 1
  • 5

2 Answers2

0

I have done it like this. This may help you out.

ImagePicker.launchCamera({},(responce)=>{
      this.setState({
          pickedImage: { uri: res.uri }
        });
      console.log(this.state.serverTime);
      const file ={
        uri : responce.uri,
        //give the name that you wish to give
        name :this.state.currentTimeInMilisec+'.jpg',
        method: 'POST',
        path : responce.path,
        type :  responce.type,
        notification: {
            enabled: true
          }
      }
       console.log(file);
    })
  }
Vidya Kabber
  • 171
  • 1
  • 16
0

I have done as below. It is working fine.

ImagePicker.launchCamera({},(responce)=>{
      const localTime = new Date().getTime();
      const file ={
        uri : responce.uri,
        //give the name that you wish to give
        name :localTime +'.jpg',
        method: 'POST',
        path : responce.path,
        type :  responce.type,
        notification: {
            enabled: true
          }
      }
       console.log(file);
    })
  }
Vidya Kabber
  • 171
  • 1
  • 16
  • 1
    Thank you for this code snippet, which might provide some limited, immediate help. A [proper explanation](https://meta.stackexchange.com/q/114762/349538) would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you’ve made. – Dwhitz Mar 27 '19 at 14:00
  • Sure, Dwhitz. :) – Vidya Kabber Mar 28 '19 at 07:25