ivpusic / react-native-image-crop-picker

iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping
MIT License
6.12k stars 1.56k forks source link

unable to get filename of an image in android #1078

Open NeerajaaG opened 5 years ago

NeerajaaG commented 5 years ago

Version

Tell us which versions you are using:

Platform

Tell us to which platform this issue is related

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

pekac commented 5 years ago

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.

NeerajaaG commented 5 years ago

It is working fine for me.

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

nwaughachukwuma commented 5 years ago

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 commented 5 years ago

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

yilinjuang commented 4 years ago

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

malikgenius commented 4 years ago

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

theneekz commented 3 years ago

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

parthkanani93 commented 3 years ago

+1

BLOCKMATERIAL commented 2 years ago

same problem

LYevhen commented 2 years ago

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

AhmedAbuelenin commented 2 years ago

+1

redjohnfrv commented 1 year ago

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'

ngoga-innocent commented 1 year ago

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

LuizFelipe16 commented 1 year ago

for me, what solved this problem was to apply a patch package, changing a line of the PickerModule.java file in node_modules

image.putString("modificationDate", String.valueOf(modificationDate));

image.putString("filename", new File(path).getName());

yarn patch-package react-native-image-crop-picker

esthor commented 1 year ago

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