Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to get filename of an image in android #1078

Open
NeerajaaG opened this issue Jul 25, 2019 · 15 comments · May be fixed by #1945
Open

unable to get filename of an image in android #1078

NeerajaaG opened this issue Jul 25, 2019 · 15 comments · May be fixed by #1945

Comments

@NeerajaaG
Copy link

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

@pekac
Copy link

pekac commented Aug 2, 2019

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

@NeerajaaG
Copy link
Author

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
Copy link

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
Copy link

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

@yilinjuang
Copy link

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

@malikgenius
Copy link

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

@theneekz
Copy link

theneekz commented Aug 3, 2021

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
Copy link

+1

@BLOCKMATERIAL
Copy link

same problem

@LYevhen
Copy link

LYevhen commented Dec 30, 2021

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
Copy link

+1

@redjohnfrv
Copy link

redjohnfrv commented Dec 22, 2022

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
Copy link

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

@LuizFelipe16
Copy link

LuizFelipe16 commented Jun 27, 2023

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

@esthor
Copy link

esthor commented Jul 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet