0

我正在使用 React-native-windows 创建 Windows 版本的 react 应用程序,我正在尝试上传文件,然后创建该文件的 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" />

但仍然收到未经授权的访问错误。

请参阅附图。

在此处输入图像描述

我也试过StorageFile,但这条线也给出了同样的错误。

StorageFile folder = await StorageFile.GetFileFromPathAsync(filepath);

谁能知道如何解决这个错误。

4

0 回答 0