我正在尝试验证从React Native中从CameraRoll选择的图像的文件大小。我的代码在Android中可用,但在IOS中不可用,因为RNFS.readFile不支持PHASSETS。还有其他方法可以在react native中验证图像的文件大小吗?
我也尝试过使用RNFS的copyAssetsFileIOS
RNFS.copyAssetsFileIOS(path, RNFS.TemporaryDirectoryPath, 0, 0)
.then(res => console.log('RES: ', res))
.catch(err => console.log('ERROR: ', err));
我还尝试过将PHASSET转换为ALASSET
path = `assets-library://asset/asset.${ext}?id=${path.substr(9)}&ext=${ext}`;
这是我的代码,可以在Android上使用,但不能在IOS上使用
RNFS.readFile(path, 'base64')
.then(res => {
// eslint-disable-next-line no-undef
const str = Platform.OS === 'ios' ? base64.decode(res) : atob(res);
const fileSize = str.length;
if (fileSize < 3000000)
this.setState({
imageSource: source,
hasExceededLimit: false,
});
else this.setState({ hasExceededLimit: true });
})
.catch(() => this.setState({ hasExceededLimit: true }));
答案 0 :(得分:0)
iOS已沙盒化,这意味着您无法直接访问App Bundle之外的任何文件。 要从iOS照片库访问照片/视频,请使用“照片框架”中的方法。