反应本地文档提取器:URI不确定,而使用的文档拾取器对本机进行了反应

发布于 2025-02-13 09:07:57 字数 706 浏览 2 评论 0原文

如何修复它:我想获取绝对路径,但是当在React Native中使用文档Picker时,File UEI是不确定的。

import { StyleSheet, Text, View,Button } from 'react-native'
import React from 'react'
import DocumentPicker from 'react-native-document-picker'
import RNFetchBlob from 'rn-fetch-blob'
import Pdf from 'react-native-open-pdf';


const openPdfex = () => {

 const openFile = () => {
  
    const res =  DocumentPicker.pick({
          type: [DocumentPicker.types.allFiles],
        });

        console.log("absolute path =====> " ,res.uri);
  }

 return (
    <View>
      <Text>openPdf</Text>
      <Button title='Open PDF' onPress={openFile}></Button>
    </View>
  )
}

How to fix it:I want to get absolute path but file uei is undefined when used document picker in react native.

import { StyleSheet, Text, View,Button } from 'react-native'
import React from 'react'
import DocumentPicker from 'react-native-document-picker'
import RNFetchBlob from 'rn-fetch-blob'
import Pdf from 'react-native-open-pdf';


const openPdfex = () => {

 const openFile = () => {
  
    const res =  DocumentPicker.pick({
          type: [DocumentPicker.types.allFiles],
        });

        console.log("absolute path =====> " ,res.uri);
  }

 return (
    <View>
      <Text>openPdf</Text>
      <Button title='Open PDF' onPress={openFile}></Button>
    </View>
  )
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瞎闹 2025-02-20 09:07:57

在文档中,它指出documentpicker.pick()返回承诺,并且由于您没有解决诺言,因此您无法从中获得URI。

  const openFile = async () => {
    try {
      const res = DocumentPicker.pick({
        type: [DocumentPicker.types.allFiles],
      });

      console.log('absolute path =====> ', res.uri);
    } catch (error) {
      console.log(error);
    }
  };

尝试一下,看看它是否有效。

In the documentation, it states that DocumentPicker.pick() returns a promise and because you did not resolve the promise, you are not able to get back the uri from it.

  const openFile = async () => {
    try {
      const res = DocumentPicker.pick({
        type: [DocumentPicker.types.allFiles],
      });

      console.log('absolute path =====> ', res.uri);
    } catch (error) {
      console.log(error);
    }
  };

Try this and see if it works.

葬﹪忆之殇 2025-02-20 09:07:57

尝试一下它有效的

const openFile = async () => {
try {
  const res = await DocumentPicker.pick({
    type: [DocumentPicker.types.allFiles],
  });
  console.log('absolute path =====> ', JSON.stringify(res[0]['uri']));
} catch (error) {
  console.log(error);
}}

Try this one it works

const openFile = async () => {
try {
  const res = await DocumentPicker.pick({
    type: [DocumentPicker.types.allFiles],
  });
  console.log('absolute path =====> ', JSON.stringify(res[0]['uri']));
} catch (error) {
  console.log(error);
}}
亣腦蒛氧 2025-02-20 09:07:57

使用documentpicker.picksingle而不是documentpicker.pick

Use DocumentPicker.pickSingle instead of DocumentPicker.pick

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文