react-native-image-crop-picker icon indicating copy to clipboard operation
react-native-image-crop-picker copied to clipboard

unable to get filename of an image in android

Open NeerajaaG opened this issue 5 years ago • 11 comments

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

  1. 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

NeerajaaG avatar Jul 25 '19 04:07 NeerajaaG

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

pekac avatar Aug 02 '19 09:08 pekac

It is working fine for me.

I used filnename= path.substring(item.path.lastIndexOf('/') + 1), to get the selected image name from its path

NeerajaaG avatar Aug 02 '19 10:08 NeerajaaG

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.(ExifInterface.java:1112) 08-04 03:55:19.060 6850 6880 W ExifInterface: at com.yalantis.ucrop.task.BitmapCropTask.crop(BitmapCropTask.java:131) 08-04 03:55:19.060 6850 6880 W ExifInterface: at com.yalantis.ucrop.task.BitmapCropTask.doInBackground(BitmapCropTask.java:91) 08-04 03:55:19.060 6850 6880 W ExifInterface: at com.yalantis.ucrop.task.BitmapCropTask.doInBackground(BitmapCropTask.java:30) 08-04 03:55:19.060 6850 6880 W ExifInterface: at android.os.AsyncTask$2.call(AsyncTask.java:305) 08-04 03:55:19.060 6850 6880 W ExifInterface: at java.util.concurrent.FutureTask.run(FutureTask.java:237) 08-04 03:55:19.060 6850 6880 W ExifInterface: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 08-04 03:55:19.060 6850 6880 W ExifInterface: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 08-04 03:55:19.060 6850 6880 W ExifInterface: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 08-04 03:55:19.060 6850 6880 W ExifInterface: at java.lang.Thread.run(Thread.java:761) 08-04 03:55:19.060 6850 6880 I BitmapCropTask: Should crop: true 08-04 03:55:19.061 6850 6880 D uCrop JNI: Crop image with CImg 08-04 03:55:19.133 6850 6850 E image-crop-picker: Promise rejected. Cannot find image data 08-04 03:55:19.152 6850 6907 I ReactNativeJS: 'error picking image', { [Error: Cannot find image data] 08-04 03:55:19.152 6850 6907 I ReactNativeJS: framesToPop: 1, 08-04 03:55:19.152 6850 6907 I ReactNativeJS: nativeStackAndroid: [], 08-04 03:55:19.152 6850 6907 I ReactNativeJS: userInfo: null, 08-04 03:55:19.152 6850 6907 I ReactNativeJS: code: 'E_NO_IMAGE_DATA_FOUND', 08-04 03:55:19.152 6850 6907 I ReactNativeJS: line: 2116, 08-04 03:55:19.152 6850 6907 I ReactNativeJS: column: 26,

nwaughachukwuma avatar Aug 04 '19 15:08 nwaughachukwuma

@NeerajaaG and @ivpusic you can follow up with progress here. Thanks!

nwaughachukwuma avatar Aug 04 '19 15:08 nwaughachukwuma

Is this resolved? still can't get filename on android

yilinjuang avatar Apr 15 '20 22:04 yilinjuang

same here, no filename going to use @NeerajaaG method .. filnename= path.substring(item.path.lastIndexOf('/') + 1)

malikgenius avatar May 12 '20 21:05 malikgenius

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...

theneekz avatar Aug 03 '21 18:08 theneekz

+1

parthkanani93 avatar Sep 21 '21 04:09 parthkanani93

same problem

BLOCKMATERIAL avatar Nov 25 '21 15:11 BLOCKMATERIAL

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

LYevhen avatar Dec 30 '21 17:12 LYevhen

+1

AhmedAbuelenin avatar May 09 '22 13:05 AhmedAbuelenin

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'

redjohnfrv avatar Dec 22 '22 04:12 redjohnfrv

same here i can't get the file name of the image

ngoga-innocent avatar May 16 '23 07:05 ngoga-innocent

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 avatar Jun 27 '23 15:06 LuizFelipe16

@LuizFelipe16 Could you open a PR so we can all benefit from this fix? 🙏

esthor avatar Jul 09 '23 20:07 esthor