I am using React-native-windows for creating windows version of react app and i am trying to upload file and then create base64 data of that file.
I am using @foqum/react-native-document-picker to upload file. It's working fine.
And i am using react-native-fs to get base64 data of uploaded file.
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;
}
}
After File upload RNFS.readFile
is called, this function call windows function, see attached image but this function not able to read uploaded file.
using (var file = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) )
Got unauthrozied access error.
I have add all required permision in package.appxmanifest
file.
<uap:Capability Name="picturesLibrary" />
<uap:Capability Name="videosLibrary" />
<rescap:Capability Name="broadFileSystemAccess" />
but still getting Unauthorized access error.
Please see attached image.
I have also tried StorageFile
but this line also give same error.
StorageFile folder = await StorageFile.GetFileFromPathAsync(filepath);
Can anyone knows how to solve this error.