How To Save/store Signature Image In App Or Phone Internal Storage. In React Native
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 stor
Solution 1:
npm install --save rn-fetch-blob
For android only AndroidManifest.xml
<!-- Required -->
<uses-permissionandroid:name="android.permission.CAMERA" /><uses-permissionandroid:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<!-- Includethis only if you are planning to use the camera roll -->
<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Includethis only if you are planning to use the microphone for video recording -->
<uses-permissionandroid:name="android.permission.RECORD_AUDIO"/>
<!-- Required -->
<applicationandroid:requestLegacyExternalStorage="true"... />// check for permissionconst checkAndroidPermission = async () => {
if (Platform.OS === 'ios') {
save();
} else {
try {
const granted = awaitPermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// Once user grant the permission start downloadingsave();
} else {
if (Platform.OS === 'android') {
ToastAndroid.show('Storage Permission denied.', ToastAndroid.SHORT);
} else {
AlertIOS.alert('Storage Permission denied.');
}
}
} catch (err) {
// To handle permission related exceptionconsole.warn('tryerr', err);
}
}
};
const save= async () => {
const paths = `${
RNFetchBlob.fs.dirs.DCIMDir
}/${newDate().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);
}
}
my this help you
Solution 2:
use this to store your photo in internal storage rn-fatch-blob if you don't understand this then told me i will share a code also to store a file in your photo with custom folder path
Post a Comment for "How To Save/store Signature Image In App Or Phone Internal Storage. In React Native"