Hi,
When im trying to load an image from gallery or camera, im getting the following uri:
/storage/emulated/0/Download/caffeine-crystals-big.jpg
To properly use UIL im constructing the following uri:
file:///storage/emulated/0/Download/caffeine-crystals-big.jpg
While trying to load the image im getting the following errors:
E/JHEAD﹕ can't open 'file:///storage/emulated/0/Download/caffeine-crystals-big.jpg'
E/BitmapFactory﹕ Unable to decode stream: java.io.FileNotFoundException: /file:/storage/emulated/0/Download/caffeine-crystals-big.jpg: open failed: ENOENT (No such file or directory)
On the other hand BitmapFactory.decodeFile(imagePath) works perfectly with the same uri.
When using:
ImageView stub = (ImageView) getView().findViewById(R.id.stubImage);
ImageLoader.getInstance().displayImage(path, stub);
Everything works fine, but when using the following:
ImageSize targetSize = new ImageSize(600, 600);
ImageLoader.getInstance().loadImage(path, targetSize, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
}
});
Im getting the errors mentioned above.
That's really weird. Are you sure you use correct URI in both cases?
Meet the same problem.
Got it, the uri should be like this:
String uri = "file://" + localImagePath;
What does localImagePath mean?
I think I'm seeing the same issue:
java.lang.Exception: Failed to copy logo from file:///storage/emulated/0/Android/data/com.dropbox.android/files/u257401473/scratch/B2DI%20Logo.jpg, failType: IO_ERROR, mimeType: null
at com.aadhk.woinvoice.util.LogoUtils$3.onLoadingFailed(ProGuard:152)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask$2.run(ProGuard:350)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6117)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.dropbox.android/files/u257401473/scratch/B2DI%20Logo.jpg: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:456)
at java.io.FileInputStream.(FileInputStream.java:76)
at java.io.FileInputStream.(FileInputStream.java:103)
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromFile(ProGuard:160)
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(ProGuard:88)
at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.getImageStream(ProGuard:93)
at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(ProGuard:73)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(ProGuard:264)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(ProGuard:237)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(ProGuard:135)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Posix.java)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:442)
at java.io.FileInputStream.(FileInputStream.java:76)
at java.io.FileInputStream.(FileInputStream.java:103)
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromFile(ProGuard:160)
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(ProGuard:88)
at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.getImageStream(ProGuard:93)
at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(ProGuard:73)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(ProGuard:264)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(ProGuard:237)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(ProGuard:135)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Code snippet:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT).setType("image/*");
activity.startActivityForResult(intent, REQUEST_PICK);
public void onActivityResult(int requestCode, int resultCode, Intent result) {
String uri = result.getData();
ImageLoader.getInstance().loadImage(uri.toString(), size, options, new ImageLoadingListener() {
// ...
});
I get this for a number of URI patterns:
/storage/emulated/0/TheFileConverter/Michael%20Lowe%203.gif: open failed: ENOENT (No such file or directory)
/storage/emulated/0/Pictures/Screenshots/2015-10-10%2023.33.22.png: open failed: ENOENT (No such file or directory)
/storage/emulated/0/Android/data/com.microsoft.skydrive/cache/stream_cache/pemartinez62%40gmail.com/542/IMG_20150928_125109.jpg: open failed: ENOENT (No such file or directory)
/storage/emulated/0/Download/BACK%20sample%201.jpg: open failed: ENOENT (No such file or directory)
/storage/emulated/0/Android/data/com.dropbox.android/files/scratch/Kassandra/kassandra%20pic.bmp: open failed: ENOENT (No such file or directory)
/storage/emulated/0/Android/data/com.tresorit.mobile/files/0020a5nuo1o9uxkujlc1em9o/%5Bmedia%5D/logo/UTS%20Tera%20Partners.png: open failed: ENOENT (No such file or directory)
/storage/sdcard0/Download/gio%20lawnmore%20and%20grass.jpg: open failed: ENOENT (No such file or directory)
/mnt/external_sd/LOGOTIPO%201.JPG: open failed: ENOENT (No such file or directory)
I wonder if this might solve it:
Uri uri = Uri.parse(fileURI);
File pdf = new File(uri.getPath());
From: http://stackoverflow.com/questions/19772856/getting-file-from-sdcard-with-uri
I can reproduce this on an LG Nexus 5 running Android 4.4.4. It happens when I use "Choose a file", see attached.
I found a work around. The original URI is this one:
file:///storage/emulated/0/Android/data/com.dropbox.android/files/u13228039/scratch/Photos/2013-Feb%20Hannah/D71_0252.jpg
It failed to load using UniversalImageLoader, with FileNotFoundException. BitmapFactory.decodeFile loads it just fine.
If I then use https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java#L257 to get a filepath, then I get this uri:
file:///storage/emulated/0/Android/data/com.dropbox.android/files/u13228039/scratch/Photos/2013-Feb Hannah/D71_0252.jpg
(Same URI, but it has a space in it instead of %20, so I guess it just got decoded)
Then it works fine with UniversalImageLoader. So I first send the URI to UIL, then if it fails, I use getPath, then try again :)
public void onLoadingFailed(final String imageUri, final View view, final FailReason failReason) {
// Try falling back if we fail to find the image
if (failReason.getCause() != null && failReason.getCause() instanceof FileNotFoundException) {
Log.d(TAG, "Falling back to FilePickerUtils.getPath: " + uri);
String path = FilePickerUtils.getPath(ctx, Uri.parse(uri));
final String fallbackUri = "file://" + path;
Log.d(TAG, "FilePickerUtils.getPath result: " + path);
ImageLoader.getInstance().loadImage(fallbackUri, size, options, new ImageLoadingListener() {
I filed this as a separate issue, it looks like UIL doesn't support encoded URIs.
https://github.com/nostra13/Android-Universal-Image-Loader/issues/1105
Maybe is late but I fixed my issue with "bitmap=BitmapFactory.decodeFile(uri);"
The crazy thing is that I didn't need to put "file://" bcos BitmapFactory accept straight way "/storage/emulated/......../bla.jpeg"
what's the solution ? i m getting same issue even using same uri in both cases
@yorkwang Thanks for the solution, it really worked!
I was just missing this: "file://"
before Uri
and nothing was working, now its working like a charm.
Most helpful comment
Got it, the uri should be like this:
String uri = "file://" + localImagePath;