将RNFetchBlob.fs.cp与uri从react-native-document-picker中获取导致错误

时间:2019-07-31 05:02:34

标签: javascript react-native-android

反应性:0.59.9, react-native-document-picker:3.2.4, rn-fetch-blob:0.10.15,

在该应用中,我使用“ react-native-document-picker”来选择手机上的文件,并获取文件的uri,然后调用“ RNFetchBlob.fs.cp(uri,destPath)”来复制文件到特定的文件夹。 但是,复制文件方法可能会失败,具体取决于“ react-native-document-picker”返回的uri。

例如,在其他目录中选择文件时, 如果uri返回为“ content://com.android.externalstorage.documents/document/primary%3ADownload%2FCopyFile.pdf”, 有用, 但是如果uri返回为“ content://com.android.providers.downloads.documents/document/17”, 那么RNFetchBlob.fs.cp将导致错误“尝试在空对象引用上调用虚拟方法'boolean java.lang.String.startsWith(java.lang.String)'”

我想它由于带有'com.android.providers.downloads'的uri格式而失败,是否有任何本机库可以处理uri,以便RNFetchBlob.fs可以在它上工作?

1 个答案:

答案 0 :(得分:1)

This是一个很好的文件/文档选择器库

运行npm install react-native-file-picker@latest --savesome changes到以下文件

  

android / settings.gradle

     

android / app / build.gradle

     

android / src / main / AndroidManifest.xml

     

MainApplication.java

您很高兴!

在您的React Native JavaScript代码中,引入本地模块:

import FilePickerManager from 'react-native-file-picker'; 继续吧!

希望这会有所帮助。