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

De/Encoding for File URI image load problem #179

Closed
zoularry opened this issue Feb 25, 2013 · 18 comments
Closed

De/Encoding for File URI image load problem #179

zoularry opened this issue Feb 25, 2013 · 18 comments
Labels

Comments

@zoularry
Copy link

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, "@#&=*+-_.,:!?()/~'%");
        ...
    }
}
@nostra13
Copy link
Owner

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?

@zoularry
Copy link
Author

zoularry commented Mar 1, 2013

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

@zoularry
Copy link
Author

zoularry commented Mar 1, 2013

@nostra13
Copy link
Owner

nostra13 commented Mar 8, 2013

I'll try ti fix it.

nostra13 added a commit that referenced this issue Mar 9, 2013
Handled local files with encoded symbols in file name
@SalmanTKhan
Copy link

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

@nostra13
Copy link
Owner

Do you use snapshot jar?

@SalmanTKhan
Copy link

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

@nostra13
Copy link
Owner

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

@SalmanTKhan
Copy link

        //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)

@nostra13
Copy link
Owner

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.

@SalmanTKhan
Copy link

Thanks Sergey, I'll just use 1.8.0 for now, sorry for the trouble.
On Mar 10, 2013 3:22 PM, "Sergey Tarasevich" notifications@github.com
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//issues/179#issuecomment-14687267
.

nostra13 added a commit that referenced this issue Mar 12, 2013
...). Not use URI class anywhere, use String class instead. Encode urls
only for network downloads.
Fixed bug for file URIs with special
characters (#179).
Improved Scheme enum, added Java docs.
@black-snow
Copy link

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

@nostra13
Copy link
Owner

And what URI string do you pass into ImageLoader?

@black-snow
Copy link

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

@nostra13
Copy link
Owner

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

@black-snow
Copy link

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?)

@AristoM
Copy link

AristoM commented Mar 16, 2015

Replacing white space with %20 is working fine for me

@hasnain-ahmad
Copy link

Replacing %20 by space works fine.

String strUri = uri.toString();
strUri = strUri.replace("%20", " ");

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

No branches or pull requests

6 participants