【问题标题】:Share message and image through whatsapp (React Native)通过whatsapp(React Native)分享消息和图像
【发布时间】:2023-03-21 05:44:01
【问题描述】:

下午好。 我正在尝试与文本共享图像,但图像未共享,共享时仅显示文本。 我根据其他主题制作了这段代码, 图像正在转换为 base64,但仍然没有出现。 注意:URI 是存储在 firebase 中的图像。

onSharePress() {
       const fs = RNFetchBlob.fs;
       let imagePath = null;
       RNFetchBlob.config({
           fileCache: true
       })
           .fetch("GET", "https://i.kinja-img.com/gawker-media/image/upload/s--HqfzgkTd--/c_scale,f_auto,fl_progressive,q_80,w_800/wp2qinp6fu0d8guhex9v.jpg")
           .then(resp => {
               imagePath = resp.path();

               return resp.readFile("base64");
           })
           .then(async base64Data => {
               var base64Data = `data:image/png;base64,` + base64Data;
               // here's base64 encoded image
               console.log(base64Data);
               const shareOptions = {
                   title: 'Title',
                   message: 'Message to share', 
                   url: base64Data,
                   subject: 'Subject'
               };
           alert(base64Data);
               await Share.share(shareOptions);
               return fs.unlink(imagePath);
           });
   }

【问题讨论】:

    标签: react-native firebase-realtime-database


    【解决方案1】:

    也许对你有帮助,这里最重要的部分(以及帮助我​​解决问题的方法)是encodeURI,关注我的代码:

    import Share from 'react-native-share'
    import RNFetchBlob from 'rn-fetch-blob'
    //
    const base64File = //base64 file
    const pdf = "data:application/pdf;base64," + base64File
    let filePath = '';
    const path = RNFetchBlob.fs.dirs.DocumentDir + '/someFileName.pdf';
    const configOptions = { fileCache: true, path };
    let fullPath = await RNFetchBlob.config(configOptions).fetch('GET', encodeURI(fileUrl))
    filePath = fullPath.path();
    let options = {
        title: 'Share via'
        type: type,
        url: filePath // (Platform.OS === 'android' ? 'file://' + filePath)
    };
    Share.open(options)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2013-03-07
      • 1970-01-01
      相关资源
      最近更新 更多