react-native-image-crop-picker
react-native-image-crop-picker copied to clipboard
unable to get filename of an image in android
Version
Tell us which versions you are using:
- react-native-image-crop-picker ^0.25.0
- react-native ^0.60.4
Platform
Tell us to which platform this issue is related
- Android
Expected behaviour
file:///storage/emulated/0/Android/data/com.techo2/cache/photo-2009714323
Actual behaviour
file:///storage/emulated/0/Android/data/com.techo2/cache/undefined
Steps to reproduce
- please help me
Attachments
// stacktrace or any other useful debug info
Love react-native-image-crop-picker? Please consider supporting our collective: 👉 https://opencollective.com/react-native-image-crop-picker/donate
Same here.
filename
attribute is missing from the image on Android platform.
If we try to hack around it and extract the name from path
, the name from path
is not the same as selected image's name.
- react-native-image-crop-picker ^0.24.1
- react-native ^0.59.8
It is working fine for me.
I used filnename= path.substring(item.path.lastIndexOf('/') + 1), to get the selected image name from its path
Hi @NeerajaaG and @ivpusic any solution to this yet? Am getting the following error, when trying to pick an image from download folder. It works Ok in the camera folder path: /storage/~/0/DCIM/Camera/...
but not with /storage/~/0/Download/...
It's saying something about exifinterface, and I tried referencing the latest exifinterface from com.android.support (28+) and androidx.exifinterface (1.1.0 beta) in my build.gradle file. Could you help with this? Could this be from the cropping lib used in this package?
Error Log
08-04 03:55:19.057 6850 6880 I ExifInterface_JNI: Raw image not detected
08-04 03:55:19.060 6850 6880 W ExifInterface: Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.
08-04 03:55:19.060 6850 6880 W ExifInterface: java.io.IOException: Invalid marker: 52
08-04 03:55:19.060 6850 6880 W ExifInterface: at android.media.ExifInterface.getJpegAttributes(ExifInterface.java:1835)
08-04 03:55:19.060 6850 6880 W ExifInterface: at android.media.ExifInterface.loadAttributes(ExifInterface.java:1475)
08-04 03:55:19.060 6850 6880 W ExifInterface: at android.media.ExifInterface.
@NeerajaaG and @ivpusic you can follow up with progress here. Thanks!
Is this resolved? still can't get filename on android
same here, no filename going to use @NeerajaaG method .. filnename= path.substring(item.path.lastIndexOf('/') + 1)
On iOS the item returned from openPicker:
{
"exif": null,
"filename": **"IMG_0005.JPG**",
"path": "/Users/username/Library/Developer/CoreSimulator/Devices/deviceId/data/Containers/Data/Application/appId/tmp/react-native-image-crop-picker/28256522-52E0-4E9B-A44A-B2D297FF3A18.jpg",
"height": 600,
"width": 600,
"data": null,
"modificationDate": null,
"localIdentifier": "identifier/L0/001",
"size": 155316,
"sourceURL": "file:///Users/username/Library/Developer/CoreSimulator/Devices/deviceId/data/Media/DCIM/100APPLE/**IMG_0005.JPG**",
"mime": "image/jpeg",
"cropRect": {
"width": 2002,
"height": 2002,
"x": 498,
"y": 0
},
"duration": null,
"creationDate": "1344462930"
}
however for Android we only have:
{
"cropRect": {
"width": 3024,
"y": 356,
"height": 3024,
"x": 0
},
"modificationDate": "1628015238000",
"size": 301013,
"mime": "image/jpeg",
"height": 600,
"width": 600,
"path": "file:///storage/emulated/0/Android/data/appId/files/Pictures/d008be59-7321-4916-b2bb-f03e72736d35.jpg",
}
If we can't get the filename, then the sourceURL is what I think we'd like to use with @NeerajaaG's method. I'm not sure if that is any easier for this package to provide in a future fix...
+1
same problem
same problem, actually slightly different. Our business needs are to show warning if user selected unsupported file, library allow to pick gif file and it converts it to jpg under the hood, but, path contain jpg, converted file and this way I'm out of control of it. It would be nice to have sourceURL same as on iOs
+1
same here, no filename going to use @NeerajaaG method .. filnename= path.substring(item.path.lastIndexOf('/') + 1)
because this method returns a string after last '/'. But in your case your file path string ends with 'undefined'
same here i can't get the file name of the image
for me, what solved this problem was to apply a patch package, changing a line of the PickerModule.java
file in node_modules
- on line 623, where you can find:
image.putString("modificationDate", String.valueOf(modificationDate));
- right below you can add this line:
image.putString("filename", new File(path).getName());
- and use command:
yarn patch-package react-native-image-crop-picker
@LuizFelipe16 Could you open a PR so we can all benefit from this fix? 🙏