Reputation: 2153
React native has a good lib like CameraRoll which allow us to access the media files of phones. However, the returned uri is missing the extension:
{ 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 } } },
If you know a way to get the extension or any work around in this case, please let me know.
Thank you in advance!
Upvotes: 2
Views: 2880
Reputation: 487
I added a boost to the camera roll package. You can use it after version 5.2.0. You can find the details here. https://github.com/react-native-cameraroll/react-native-cameraroll/pull/440
Now you can use it like this;
CameraRoll.getPhotos({
include: ['fileExtension'],
})
Upvotes: 1
Reputation: 21
I have solved this using the 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
} }`
Upvotes: 1
Reputation: 2153
I have a work around, the returned extension is not pretty but it is useable:
From the file RNCCameraRollManager.m:
NSString *const extension = [asset valueForKey: @"uniformTypeIdentifier"];
@"extension": extension,
Now you have the extension.
Here is the environment:
"@react-native-community/cameraroll": "1.0.3",
"react": "16.8.3",
"react-native": "0.59.5"
Upvotes: 1