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

Cannot display some local files with a space in their name #371

Closed
markuspfeiffer opened this issue Aug 16, 2013 · 10 comments
Closed

Cannot display some local files with a space in their name #371

markuspfeiffer opened this issue Aug 16, 2013 · 10 comments

Comments

@markuspfeiffer
Copy link

I'm loading images from the local storage using the following code:

if (file.exists() && ContentType.isImage(file)) {
    final String uri = Uri.fromFile(file).toString();
    ImageLoader.getInstance().displayImage(uri, imageView);
}

This fails with the following exception:

/storage/emulated/0/.../ad%20(1).jpg: open failed: ENOENT (No such file or directory)
java.io.FileNotFoundException: /storage/emulated/0/.../ad%20(1).jpg: open failed: ENOENT (No such file or directory)

// path manually truncated, due to length

It looks like the file name extracted from the URL does not decode the %20 to " ".

@markuspfeiffer
Copy link
Author

For verification purposes I changed the code that renames duplicate files to produce "file_(n)" instead of "file (n)". Images are now loaded correctly.

@rgrocha
Copy link

rgrocha commented Aug 16, 2013

I think %20 is not translated automatically to the space char by the file system, it's an url encoded char.
If you are using an url extracted from somewhere, try tu use java.net.URI to decode the url and extract the required parameter from the query.

@markuspfeiffer
Copy link
Author

As you can see above, I convert the file's path to an Uri and pass that to the image loader, as required. However, the image loader then fails to load the file, i.e. this is a bug in Universal Image Loader, not my code.

The image loader does not seem to convert %20 to " " when decoding the URI to access the local file, which leads to the file not being found since the file's name on disk is "ad (1).jpg" and not "ad%20(2).jpg". When I changed the file's name to "ad_(1).jpg" the image loader successfully loaded the file.

@Dcodechef
Copy link

I am also facing the same issue, kindly suggest the possible solution.
It's only with files have space in their path.

@Dcodechef
Copy link

Hey,
Just solved the issue.
After getting uri using:
Uri fileUri=Uri.fromfile(fileObject);

USE: setUrl(Uri.decode(fileUri));

Cheers!

@ghost
Copy link

ghost commented Aug 28, 2013

@Dcodechef How are you using setUri? (on what?)

@Dcodechef
Copy link

Use decoded uri where ever you are passing in image loader for local files.
Hope this will help.

@markuspfeiffer
Copy link
Author

I can confirm that this solution works. My code now looks as follows:

if (file.exists() && ContentType.isImage(file)) {
    final String uri = Uri.fromFile(file).toString();
    final String decoded = Uri.decode(uri);

    ImageLoader.getInstance().displayImage(decoded, imageView);
}

I'll mark the issue as closed since this solution is really simple to use. Thanks a lot @Dcodechef.

@markuspfeiffer
Copy link
Author

The Uri.decode() is only really needed for local files with a blank in
their name. In your case the issue seems to be a malformed path, look at
the start of your path:

"/storage/emulated/0/storage/emulated/0"

There seems to be an issue with the code that creates your path. For
some reason the "/storage/emulated/0" is added twice.

On 17.03.2015 03:29, zoumy wrote:

@Dcodechef @markuspfeiffer I got the same issue,I tried to use Uri.decode(),but java.io.FileNotFoundException: /storage/emulated/0/storage/emulated/0/Pictures/Screenshots/Screenshot_2015-03-12-17-31-02.png

My code:
ImageLoader.getInstance().displayImage(Uri.decode(data.get(position).toString()),holder.imageView);
I couldn't show my local images to gridView.


Reply to this email directly or view it on GitHub:
#371 (comment)

@wangduanqing5945
Copy link

I have same problem when path contains chinese.

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

No branches or pull requests

4 participants