React-native-windows未授权访问错误

时间:2019-06-03 06:59:38

标签: react-native react-native-fs react-native-windows

我正在使用React-native-windows创建React应用的Windows版本,我试图上传文件,然后创建该文件的base64数据。

我正在使用@foqum/react-native-document-picker上传文件。一切正常。

我正在使用react-native-fs来获取上传文件的base64数据。

const res = await DocumentPicker.pick({
                    type: [DocumentPicker.types.allFiles],
                });
                console.log(
                    res.uri,
                    res.type, // mime type
                    res.name,
                    res.size
                );
                var url = res.uri;

                RNFS.readFile(url, 'base64')
                    .then((result) => {
                        Alert.alert("", "File Uploaded successfully.");

                    })
                    .catch((err) => {
                        Alert.alert("", "File not uploaded.")
                    });
            } catch (err) {
                if (DocumentPicker.isCancel(err)) {
                    // User cancelled the picker, exit any dialogs or menus and move on
                } else {
                    Alert.alert("", "File not uploaded.")
                    throw err;
                }
            }

调用文件上传RNFS.readFile后,此函数将调用Windows函数,请参见附件图像,但此函数无法读取上传的文件。

using (var file = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) ) 

出现未经授权的访问错误。

我已在package.appxmanifest文件中添加了所有必需的置换。

<uap:Capability Name="picturesLibrary" /> 
<uap:Capability Name="videosLibrary" />
<rescap:Capability Name="broadFileSystemAccess" />

但仍然出现未经授权的访问错误。

请参阅附件图片。

enter image description here

我也尝试过StorageFile,但此行也给出了相同的错误。

StorageFile folder = await StorageFile.GetFileFromPathAsync(filepath);

任何人都知道如何解决此错误。

0 个答案:

没有答案