如何在应用程序或 phone 内部存储中 save/store 签名图像。在本机反应中

How to save/store signature image in app or phone internal storage. in react native

我是 React Native 的新手。我正在尝试将签名存储在我的移动内部存储器中。或在应用程序本身。但我不知道如何将此签名图像存储在 phone 内部存储或应用程序存储中。请帮忙 。这是代码

base64:null,

_onSaveEvent = (result) => {

  this.setState({base64: result.pathName})
  console.log(this.state.base64)


                            <SignatureCapture
                              style={styles.signature}
                              ref="sign"
                              onSaveEvent={this._onSaveEvent}
                              onDragEvent={this._onDragEvent}
                              showNativeButtons={false}
                              showTitleLabel={false}
                              viewMode={'portrait'}
                            />
}

result.pathNamereturn这条路=

/storage/emulated/0/saved_signature/signature.png

但知道文件夹调用者 saved_signature。那怎么办呢

使用它在内部存储器中存储您的照片rn-fatch-blob 如果你不明白这一点,那么告诉我我也会分享一个代码,用自定义文件夹路径在你的照片中存储一个文件

    npm install --save rn-fetch-blob

For android only AndroidManifest.xml
<!-- Required -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<!-- Include this only if you are planning to use the camera roll -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- Include this only if you are planning to use the microphone for video recording -->
<uses-permission android:name="android.permission.RECORD_AUDIO"/>


<!-- Required -->
<application  android:requestLegacyExternalStorage="true" ... />

// check for permission
const checkAndroidPermission = async () => {
    if (Platform.OS === 'ios') {
      save();
    } else {
      try {
        const granted = await PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
        );
        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
          // Once user grant the permission start downloading

          save();
        } else {
          if (Platform.OS === 'android') {
            ToastAndroid.show('Storage Permission denied.', ToastAndroid.SHORT);
          } else {
            AlertIOS.alert('Storage Permission denied.');
          }
        }
      } catch (err) {
        // To handle permission related exception
        console.warn('tryerr', err);
      }
    }
  };
  
   const save= async () => {
      const paths = `${
        RNFetchBlob.fs.dirs.DCIMDir
      }/${new Date().getTime()}.jpg`; // where u need to put that 
      try {
        RNFetchBlob.fs
          .writeFile(paths, data.base64, 'base64')//data.base64 is your photo with convert base64
          .then((value) => {
              RNFetchBlob.fs
                .scanFile([{path: paths}]) //after save to notify gallry for that
                .then(() => {
                  console.log('scan file success');
                })
                .catch((err) => {
                  console.log('scan file error');
                });
          })
          .catch((e) => console.log(e.message));
      } catch (error) {
        console.log('fileerror', error.message);
      }
    
}

我这对你有帮助