react-native - 从 CameraRoll.getPhotos() 获取文件名 [React Native IOS]
问题描述
如何从中获取文件名CameraRoll.getPhotos()
?
CameraRoll.getPhotos({ first: 1000000, assetType: "All", groupTypes: "All" })
.then(res => {
console.log(res)
})
我可以获取文件 uri和文件类型,但不能获取文件名。我的意思是没有返回文件名。
这是输出:
解决方案
我已经使用 expo-media-library https://docs.expo.io/versions/latest/sdk/media-library/###解决了这个问题
const getLocalUri = async () => {
let uri = "ph://ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED/L0/001"
let myAssetId = uri.slice(5);
let returnedAssetInfo = await MediaLibrary.getAssetInfoAsync(myAssetId);
console.log(returnedAssetInfo.localUri); // you local uri link to get the file
}
如果不使用 Expo,请记住安装 unimodules:https ://www.npmjs.com/package/react-native-unimodules
来源:https ://github.com/react-native-community/react-native-cameraroll/issues/52#issuecomment-564641652
推荐阅读
- android - 使用 Osmdriod 在地图上显示 Android 设备内存中的 KML 文件
- javascript - 循环通过 JSON 时无法读取未定义的属性“0”
- excel - 如何根据特定的幻灯片输入将幻灯片从现有演示文稿复制到新演示文稿?
- swift - 如何减少另一个函数中的步进值?
- javascript - 如何在自动完成上应用 .on() 方法?
- angular - 其他组件的角度更改 RouteLink 并添加额外的查询参数
- flutter - Image.asset中图像的圆角抖动?
- swift - 限制 Firestore 检索数据的频率
- reactjs - 如果时间为字符串,如何在反应材料 ui KeyboardDatePicker 中编辑时间?
- javascript - 使用 Google Classroom 浏览器 API 时避免暴露 API 密钥和客户端 ID