我正在尝试通过各种可用设备的应用程序(例如 WhatsApp、Skype、电子邮件等)将从相机或图库中拍摄的图像共享到其他设备 我发现提供了“共享”功能,但根据我的知识和研究,它只允许共享文本数据。
有人知道如何通过 React Native 应用程序共享图像吗?
提前致谢。
最佳答案
解决方案:
获取要转换为base64的图像的路径。
对于共享图像使用:react-native-share lib share
要访问设备目录,我建议使用:rn-fetch-blob。 Wikki lib
dwFile(file_url) { let imagePath = null; RNFetchBlob.config({ fileCache: true }) .fetch("GET", file_url) // the image is now dowloaded to device's storage .then(resp => { // the image path you can use it directly with Image component imagePath = resp.path(); return resp.readFile("base64"); }) .then(async base64Data => { var base64Data = `data:image/png;base64,` + base64Data; // here's base64 encoded image await Share.open({ url: base64Data }); // remove the file from storage return fs.unlink(imagePath); }); }
希望这有帮助。
关于reactjs - React Native 分享图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46295905/