我正在从 URI 下载文件,并尝试在另一个应用程序中打开它。该文件是一个简单的 .xlsx 电子表格。我正在使用 Android 设备进行测试。下面的代码是一个可重现的示例:
import React, { useCallback } from 'react'
import { Button, View } from 'react-native'
import * as Linking from 'expo-linking'
import * as FileSystem from 'expo-file-system'
const App = () => {
const download = useCallback(async () => {
const downloadUri = 'http://url.to/my/spreadsheet.xlsx')
const localPath = `${FileSystem.cacheDirectory}spreadsheet.xlsx`
try {
await FileSystem.downladAsync(downloadUri, localPath)
.then(async ({ uri }) => {
const contentURL = await FileSystem.getContentUriAsync(uri)
await Linking.openURL(contentURL)
})
.catch((err) => console.log(err))
} catch (err) { …Run Code Online (Sandbox Code Playgroud)