reactjs - React Native 分享图片

标签 reactjs react-native

我正在尝试通过各种可用设备的应用程序(例如 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/

相关文章:

javascript - 在 componentDidMount 中异步获取后更改/处理数据

javascript - iOS 11.4 Safari 不遵守 'touch-action: manipulation'

javascript - React 应用程序渲染空页面,控制台没有错误

ios - 在 VS Code : add configuration for iOS Device to launch. json 中 react native

react-native - native react :undefined is not an object (evaluating '_this2.props.navigation.navigate' )

android - 修复了在 native 中滚动时的导航栏

javascript - mobx 商店更改后更新选项卡导航器上的徽章

reactjs - 在 react webapp 中审计和时间记录用户行为的最佳解决方案?

javascript - 无法使用带有 Linking.openURL ('app-settings' 的 expo 打开设置)

react-native - 未强制执行 ReactiveSearch 默认查询