react native - Camera Roll 返回的 uri 没有文件扩展名
react native - Camera Roll returned uri does not have file's extension
React native 有一个很好的lib,比如CameraRoll,它允许我们访问手机的媒体文件。但是,返回的 uri 缺少扩展名:
{ node:
{ timestamp: 1344461389.8,
type: 'image', <= it is used to be 'image/png' instead of 'image'
group_name: 'Camera Roll',
location:
{ altitude: 0,
longitude: -14.538611666666666,
latitude: 64.752895,
heading: 0,
speed: 0.8999988197665498 },
image:
{ width: 1668,
uri: 'ph://99D53A1F-FEEF-40E1-8BB3-7DD55A43C8B7/L0/001', <= there is no file's extension
height: 2500,
isStored: true,
playableDuration: 0 } } },
如果您知道获取扩展程序的方法或在这种情况下有任何解决方法,请告诉我。
提前致谢!
我有一个变通办法,返回的扩展不是很漂亮,但它是可用的:
来自文件 RNCCameraRollManager.m:
请添加这两行
NSString *const extension = [asset valueForKey: @"uniformTypeIdentifier"];
和
@"extension": extension,
现在你有了扩展。
这里是环境:
"@react-native-community/cameraroll": "1.0.3",
"react": "16.8.3",
"react-native": "0.59.5"
我已经使用 expo-media-library 解决了这个问题
https://docs.expo.io/versions/latest/sdk/media-library
async myFunc() {
let uri = "ph://ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED/L0/001"
let myAssetId = uri.slice(5);
let returnedAssetInfo = await MediaLibrary.getAssetInfoAsync(myAssetId);
returnedAssetInfo // you will have all the information in here
} }`
React native 有一个很好的lib,比如CameraRoll,它允许我们访问手机的媒体文件。但是,返回的 uri 缺少扩展名:
{ node:
{ timestamp: 1344461389.8,
type: 'image', <= it is used to be 'image/png' instead of 'image'
group_name: 'Camera Roll',
location:
{ altitude: 0,
longitude: -14.538611666666666,
latitude: 64.752895,
heading: 0,
speed: 0.8999988197665498 },
image:
{ width: 1668,
uri: 'ph://99D53A1F-FEEF-40E1-8BB3-7DD55A43C8B7/L0/001', <= there is no file's extension
height: 2500,
isStored: true,
playableDuration: 0 } } },
如果您知道获取扩展程序的方法或在这种情况下有任何解决方法,请告诉我。
提前致谢!
我有一个变通办法,返回的扩展不是很漂亮,但它是可用的:
来自文件 RNCCameraRollManager.m:
请添加这两行
NSString *const extension = [asset valueForKey: @"uniformTypeIdentifier"];
和
@"extension": extension,
现在你有了扩展。
这里是环境:
"@react-native-community/cameraroll": "1.0.3",
"react": "16.8.3",
"react-native": "0.59.5"
我已经使用 expo-media-library 解决了这个问题 https://docs.expo.io/versions/latest/sdk/media-library
async myFunc() {
let uri = "ph://ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED/L0/001"
let myAssetId = uri.slice(5);
let returnedAssetInfo = await MediaLibrary.getAssetInfoAsync(myAssetId);
returnedAssetInfo // you will have all the information in here
} }`