首页 > 解决方案 > 从 CameraRoll.getPhotos() 获取文件名 [React Native IOS]

问题描述

如何从中获取文件CameraRoll.getPhotos()

CameraRoll.getPhotos({ first: 1000000, assetType: "All", groupTypes: "All" })
  .then(res => {
    console.log(res)
})

我可以获取文件 uri文件类型,但不能获取文件名。我的意思是没有返回文件名。

这是输出:

在此处输入图像描述

标签: react-nativefilenamescamera-roll

解决方案


我已经使用 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


推荐阅读