0

我使用 react-native-share 为 android 创建了一个共享函数,我将数据转换为 base64,然后按如下方式共享

shareImage= (item) => {
  RNFetchBlob.fetch('GET', `some url`+item._id)
    .then(resp => {
      console.log('response : ', typeof resp);
      console.log('fff', resp.data);
      let base64image = resp.data;
      share('data:image/png;base64,' + base64image);
    })
    .catch(err => {
      err && console.log(err);
    });

  share = base64image => {
    console.log('base64image : ', base64image);
    var shareOptions = {
      title:item.title,
      url: base64image,
      // message: 'https://somelink.com some message',
      subject: 'Subject'
    };

    Share.open(shareOptions)
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        err && console.log(err);
      });
    }
  }; 

共享图像和从 url 获取的数据,但是当我运行它时,我得到一个错误,因为 BAD BASE-64,我的日志是:

 response :  object
 LOG  fff <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /homeundefined</pre>
</body>
</html>

 LOG  base64image :  data:image/png;base64,<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /homeundefined</pre>
</body>
</html>

 LOG  {"error": "bad base-64"}

谁能告诉我哪里出错了?

4

0 回答 0