为了下载资产,在将react-native-fs与React Native一起使用时,需要设置一个Authorization标头。
在文档之后,标题设置如下:
const options = {
headers: {
Authorization: `Bearer ${accessToken}`,},fromUrl: url,toFile: path,};
// const permission = await insurePermissions();
const task = RNFS.downloadFile(options);
它在iOS上运行完美,但是在Android上,使用运行Android 6、8、9或10的模拟器,则不会发送标头,因此服务器会返回错误的其他资产,因为用户不是被认证。
如何在Android中使用react-native-fs设置Authentication标头?