反应原生共享图像

新手上路,请多包涵

我正在尝试通过各种可用设备的应用程序(例如whatsApp、skype、电子邮件等)将从相机或画廊拍摄的图像分享到其他设备。我发现提供了“分享”功能,但根据我的知识和研究,它只允许共享文本数据。

有人对通过本机应用程序共享图像有任何想法吗?

提前致谢。

原文由 Rohan Kangale 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 375
1 个回答

解决方案:

  • 获取要转换base64的图片路径。

  • 对于共享图像使用:react-native-share lib share

  • 要访问设备目录,我建议使用:rn-fetch-blob。 维基库

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

希望这可以帮助。

原文由 Bruno Araujo 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题