【问题标题】:[Unhandled promise rejection: Error: Location "imageURL" isn't readable - Expo React Native[未处理的承诺拒绝:错误:位置“imageURL”不可读 - Expo React Native
【发布时间】:2021-09-09 13:49:42
【问题描述】:

我正在尝试使用 expo FileSystem 将 firebase 图像 URL 转换为 base64,但出现以下错误。

[未处理的承诺拒绝:错误:位置“https://pngimg.com/uploads/birds/small/birds_PNG108.png”不可读 - Expo React Native

URL 非常完美,因为我可以在浏览器中打开它。我正在尝试跟踪 URL,并尝试了多个其他 URL。

https://pngimg.com/uploads/birds/small/birds_PNG108.png

以下是我的代码。

import * as FileSystem from 'expo-file-system';
<TouchableOpacity onPress={async () => {
      const base64 = await FileSystem.readAsStringAsync('https://pngimg.com/uploads/birds/small/birds_PNG108.png', { encoding: 'base64' });
        Share.share(
          {
            title: 'test title',
            url: item.url,
          },
          {
            excludedActivityTypes: [
              
            ],
          }
        );
     }}>
    </TouchableOpacity>
    
  )}

在任何论坛上都找不到解决此问题的方法。

【问题讨论】:

  • AFAIK FileSystem.readAsStringAsync 用于 URI 而不是 URL。下载文件存储在FileSystem.documentDirectory/…。然后您可以使用FileSystem.readAsStringAsync访问存储的文件
  • 谢谢,它现在正在转换为base64,但是当我分享时,它说不能发送空消息。你有什么想法吗?
  • 另外请将其作为答案发布,以便我可以为其他人接受。

标签: javascript react-native react-hooks expo


【解决方案1】:

也许你应该使用

import * as Sharing from 'expo-sharing';

将图像临时保存在光盘上并使用 uri 共享图像。

比

import { Share} from 'react-native';

【讨论】:

  • 我收到can't send empty message error
猜你喜欢
  • 2016-12-15
  • 1970-01-01
  • 1970-01-01
  • 2021-06-25
  • 2017-12-20
  • 1970-01-01
  • 2018-10-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多