Android-universal-image-loader: De/Encoding for File URI image load problem

Created on 25 Feb 2013  Â·  18Comments  Â·  Source: nostra13/Android-Universal-Image-Loader

For an image file: /storage/sdcard0/groupurchase/cache/http%3A%2F%2Fd2.lashouimg.com%2Fzt_mobile_220%2F201211%2F29%2F135417696321262100.jpg

imageLoader tries to load an decoded file path which is incorrect:

02-25 13:20:51.085: E/ImageLoader(27155): java.io.FileNotFoundException: /storage/sdcard0/groupurchase/cache/http:/d2.lashouimg.com/zt_mobile_220/201211/29/135417696321262100.jpg: open failed: ENOENT (No such file or directory)

It should keep the encoded string as it is, and read by stream.

The problem is caused by imageloader code below:

final class ImageLoadingInfo {
...
    public ImageLoadingInfo(String uri, ImageView imageView, ImageSize targetSize, DisplayImageOptions options, ImageLoadingListener listener, ReentrantLock loadFromUriLock) {
        this.uri = Uri.encode(uri, "@#&=*+-_.,:!?()/~'%");
        ...
    }
}
Bug

All 18 comments

No, this is not the reason of problem. Actually I can't catch the problem in debug.
Are you sure your file is really exists?

Yes. the file exists...
Phone 4.2.1, GT-I9100, CyanogenMod

Another example:

The value passing in

coverPhotoFilePath:/storage/sdcard0/picasa_tool/google%252520plus-1.jpg

Exception thrown by loader:

03-01 09:40:21.880: E/ImageLoader(13598): /storage/sdcard0/picasa_tool/google%2520plus-1.jpg: open failed: ENOENT (No such file or directory)
03-01 09:40:21.880: E/ImageLoader(13598): java.io.FileNotFoundException: /storage/sdcard0/picasa_tool/google%2520plus-1.jpg: open failed: ENOENT (No such file or directory)

adb shell ls

shell@android:/storage/sdcard0/picasa_tool $ ls goo*
ls goo*
google%252520plus-1.jpg

result

"25" was removed by imageloader.
google%252520plus-1.jpg --> google%2520plus-1.jpg

I'll try ti fix it.

Still having this issue even with your changes, I'm also on CM10 4.2.2 (Samsung Vibrant).

Do you use snapshot jar?

I always grab a zip and build the lib on my own.

Show me please your config, display options and URI of file which you pass to displayImage(...) method.

        //Config ImageLoader
        DisplayImageOptions.Builder lBuilder = new DisplayImageOptions.Builder();
        lBuilder.showStubImage(R.drawable.ic_launcher);
        lBuilder.bitmapConfig(Integer.parseInt(mPrefs.getString(PrefsActivity.KEY_APP_BITMAP_TYPE, "0")) == 0 ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);

        if (mPrefs.getBoolean(
                PrefsActivity.KEY_APP_MEMCACHE_ENABLED_PREFERENCE, true))
            lBuilder.cacheInMemory();
        if (mPrefs.getBoolean(
                PrefsActivity.KEY_APP_DISCCACHE_ENABLED_PREFERENCE, true))
            lBuilder.cacheOnDisc();

        mDisplayOptions = lBuilder.build();

        // Create configuration for ImageLoader
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
        .discCache(new UnlimitedDiscCache(StorageHelper.getCacheDir()))
        .threadPoolSize(5)
        .threadPriority(Thread.NORM_PRIORITY-1)
        .defaultDisplayImageOptions(mDisplayOptions)
        .build(); // --

        mImageLoader.init(config);
String lCoverURL = "file:///"+ lCoverFile.getAbsolutePath();

URI = file:////storage/sdcard0/My Manga Reader/Naruto/cover.png
Error

03-10 12:24:43.448: E/ImageLoader(5349): /storage/sdcard0/My%20Manga%20Reader/Cache/1526703973: open failed: ENOENT (No such file or directory)
03-10 12:24:43.448: E/ImageLoader(5349): java.io.FileNotFoundException: /storage/sdcard0/My%20Manga%20Reader/Cache/1526703973: open failed: ENOENT (No such file or directory)
03-10 12:24:43.448: E/ImageLoader(5349):    at libcore.io.IoBridge.open(IoBridge.java:416)
03-10 12:24:43.448: E/ImageLoader(5349):    at java.io.FileInputStream.<init>(FileInputStream.java:78)
03-10 12:24:43.448: E/ImageLoader(5349):    at java.io.FileInputStream.<init>(FileInputStream.java:105)
03-10 12:24:43.448: E/ImageLoader(5349):    at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromFile(BaseImageDownloader.java:141)

Yes, I see the problem and I'll think about a solution. I guess ImageDownloader is needed in API changes but I really want to avoid it.

At this moment I can recommend you to avoid using of spaces (" ") in your file paths.

Thanks Sergey, I'll just use 1.8.0 for now, sorry for the trouble.
On Mar 10, 2013 3:22 PM, "Sergey Tarasevich" [email protected]
wrote:

Yes, I see the problem and I'll think about a solution. I guess
ImageDownloader is needed in API changes but I really want to avoid it.

At this moment I can recommend you to avoid using of spaces (" ") in your
file paths.

—
Reply to this email directly or view it on GitHubhttps://github.com/nostra13/Android-Universal-Image-Loader/issues/179#issuecomment-14687267
.

Actually this isn't (fully) fixed. I'm using 1.9.3 and get the above error when loading images from sdcard from a directory containing whitespaces (%20).

And what URI string do you pass into ImageLoader?

/sdcard/Android/data/my.package/files/Pictures/directory%20containing%20whitespaces/some_image.jpg

You should pass "/sdcard/Android/data/my.package/files/Pictures/directory containing whitespaces/some_image.jpg"

Aight, that's why you changed it from Uri to String ...
An overloaded constructor w/ Uri would be great. Error happend due to using Uri.toString() which gives me %20 for whitespaces instead of the whitespace. Or it should be mentioned that %20 (and others) do not work (is it noted somewhere already?)

Replacing white space with %20 is working fine for me

Replacing %20 by space works fine.

String strUri = uri.toString();
strUri = strUri.replace("%20", " ");
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZuzooVn picture ZuzooVn  Â·  10Comments

fistuk picture fistuk  Â·  13Comments

androidmalin picture androidmalin  Â·  10Comments

o-antsiferov picture o-antsiferov  Â·  16Comments

AmirMukhtar16 picture AmirMukhtar16  Â·  9Comments