Picasso: Cannot show image from assets folder

Created on 16 Dec 2013  Â·  8Comments  Â·  Source: square/picasso

I follow guide to load image from assets:
Picasso.with(context).load(new File("/thumb/101.jpg")).into(imageView);

But get this error:
12-16 11:40:33.805: E/JHEAD(22889): can't open '/thumb/101.jpg'

Do I use wrong path of image in assets? Or any reason make image cannot be loaded?

Thank you for your support.

Most helpful comment

You can just pass the string. No need to create the File object.
On Dec 15, 2013 9:06 PM, "anticafe" [email protected] wrote:

I try as you suggest:
File file = new File("file:///android_asset/thumb/101.jpg");
Picasso.with(context).load(file).into(imageView);

But still get error:
12-16 12:04:17.085: E/JHEAD(27402): can't open
'/file:/android_asset/thumb/101.jpg'

—
Reply to this email directly or view it on GitHubhttps://github.com/square/picasso/issues/332#issuecomment-30635156
.

All 8 comments

You need to prefix the path with file:///android_asset/
On Dec 15, 2013 8:47 PM, "anticafe" [email protected] wrote:

I follow guide to load image from assets:
Picasso.with(context).load(new File("/thumb/101.jpg")).into(imageView);

But get this error:
12-16 11:40:33.805: E/JHEAD(22889): can't open '/thumb/101.jpg'

Do I use wrong path of image in assets? Or any reason make image cannot be
loaded?

Thank you for your support.

—
Reply to this email directly or view it on GitHubhttps://github.com/square/picasso/issues/332
.

I try as you suggest:
File file = new File("file:///android_asset/thumb/101.jpg");
Picasso.with(context).load(file).into(imageView);

But still get error:
12-16 12:04:17.085: E/JHEAD(27402): can't open '/file:/android_asset/thumb/101.jpg'

You can just pass the string. No need to create the File object.
On Dec 15, 2013 9:06 PM, "anticafe" [email protected] wrote:

I try as you suggest:
File file = new File("file:///android_asset/thumb/101.jpg");
Picasso.with(context).load(file).into(imageView);

But still get error:
12-16 12:04:17.085: E/JHEAD(27402): can't open
'/file:/android_asset/thumb/101.jpg'

—
Reply to this email directly or view it on GitHubhttps://github.com/square/picasso/issues/332#issuecomment-30635156
.

Thank you so much. Finally it works.

Should you edit your instruction at http://square.github.io/picasso/ > "Resource loading" to avoid any confusion later?

Loading from a file is different than loading from assets. We can add another example to show assets, I suppose.

Closing.

i have a same problem when i try to load image from SDcard

final String filePath = SignalApplication.IMAGE + "/" + marketId + "/" + productId + "/" + "showCase";
Uri uri = Uri.parse(filePath + "/" + imageFileName);
File pdf = new File(uri.getPath());
Picasso.with(context)
        .load(pdf)
        .resize(cellSize, cellSize)
        .centerCrop()
        .into(holder.ivPhoto, new Callback() {
            @Override
            public void onSuccess() {
                animatePhoto(holder);
            }
            @Override
            public void onError() {
                Log.e("Error "," opening image"+filePath);
            }
        });

@tux-world : you're awesome, Thanks

Was this page helpful?
0 / 5 - 0 ratings