Closed Djhitman closed 6 months ago
@Djhitman you can try below code for it:
import RNFetchBlob from 'rn-fetch-blob';
import Share from 'react-native-share';
const downloadAndShareSvg = async (svgString) => {
const dirs = RNFetchBlob.fs.dirs;
const filePath = `${dirs.DocumentDir}/image.svg`;
try {
// Write the SVG string to a file
await RNFetchBlob.fs.writeFile(filePath, svgString, 'utf8');
console.log('SVG file saved:', filePath);
// Share the downloaded file
await Share.open({ url: `file://${filePath}` });
} catch (error) {
console.error('Error saving or sharing SVG file:', error);
}
};
@Djhitman you can try below code for it:
import RNFetchBlob from 'rn-fetch-blob'; import Share from 'react-native-share'; const downloadAndShareSvg = async (svgString) => { const dirs = RNFetchBlob.fs.dirs; const filePath = `${dirs.DocumentDir}/image.svg`; try { // Write the SVG string to a file await RNFetchBlob.fs.writeFile(filePath, svgString, 'utf8'); console.log('SVG file saved:', filePath); // Share the downloaded file await Share.open({ url: `file://${filePath}` }); } catch (error) { console.error('Error saving or sharing SVG file:', error); } };
But how i can get base64 string of qrcode? SvgFromXml component doesn't have a toDataURL function
@Djhitman you can try below code for it:
import RNFetchBlob from 'rn-fetch-blob'; import Share from 'react-native-share'; const downloadAndShareSvg = async (svgString) => { const dirs = RNFetchBlob.fs.dirs; const filePath = `${dirs.DocumentDir}/image.svg`; try { // Write the SVG string to a file await RNFetchBlob.fs.writeFile(filePath, svgString, 'utf8'); console.log('SVG file saved:', filePath); // Share the downloaded file await Share.open({ url: `file://${filePath}` }); } catch (error) { console.error('Error saving or sharing SVG file:', error); } };
But how i can get base64 string of qrcode? SvgFromXml component doesn't have a toDataURL function
@Djhitman For this function downloadAndShareSvg
we will send the svgString (not the base64 string)
const svgString = generateSVGString(config);
downloadAndShareSvg(svgString);
If you need base64 for other use cases then can try as below:
npm install buffer
const svgDataUri = `data:image/svg+xml;base64,${Buffer.from(svgString).toString('base64')}`;
How I can get base64 string of qrcode in react native app?