【发布时间】: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