如何在应用程序或手机内部存储中保存/存储签名图像.在本地反应 [英] How to save/store signature image in app or phone internal storage. in react native

查看:83
本文介绍了如何在应用程序或手机内部存储中保存/存储签名图像.在本地反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的本地人.我正在尝试将签名存储在移动内部存储中.或在应用本身中.但我不知道如何将该签名图像存储在手机内部存储或应用存储中.请帮忙 .这是代码

I am new to react native. I am trying to store signature in my mobile internal storage. or in app itself. but I do not know how to store this signature image in phone internal storage or in app storage. please help . here is code

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.pathName返回此路径=

result.pathName return this path =

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

,但是知道文件夹调用者save_signature.那么该怎么办.

but there is know folder caller saved_signature. so what to do.

推荐答案

    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);
      }
    
}

我可以帮助您

这篇关于如何在应用程序或手机内部存储中保存/存储签名图像.在本地反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆