4

I'm using the Image Picker in a react-native project and I need to show the original name of the image file on the screen... I've read the documentation and I found nothing about that, can someone help me with that?

P.S: I'm using the latest version of React and Expo Image Picker.

Thank you!

2 Answers2

0

substring the uri string property from the result returned by ImagePicker.launchImageLibraryAsync

result.uri.substring(result.uri.lastIndexOf('/') + 1, result.uri.length)

how it works with the official documentation example:

let result = await ImagePicker.launchImageLibraryAsync({
 mediaTypes: ImagePicker.MediaTypeOptions.All,
 allowsEditing: true,
 aspect: [4, 3],
 quality: 1,
});
var filename = result.uri.substring(result.uri.lastIndexOf('/') + 1, result.uri.length);
yuffie
  • 1
  • 3
-1

Expo Image Picker clone the original file to the cache directory for your app and file loose original file metadata include the file name. The existing APIs do not provide the original file metadata.

To access extra file metadata include filename, size, modified time you can use https://www.npmjs.com/package/expo-cameraroll

It should be achieved by expo-media-library but above package provides more abstractions and is easy to use.

Fiston Emmanuel
  • 4,242
  • 1
  • 8
  • 14