Failed to load resource when loading image - android

I am making a project for image loading but whenever I try to load an image into circle image view through glide but whenever I run the app, the image view goes blank and error comes up from glide.
dp = view.findViewById(R.id.circleView);
GlideApp
.with(getActivity())
.load(serverResponse.getMessage().getPic())//C:/Apache24/htdocs/app2/User Files/User Id-102/User id 102.jpg
.listener(new RequestListener<Drawable>() {
#Override
public boolean onLoadFailed(#Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
// log exception
Toast.makeText(getActivity(), "Error loading image", Toast.LENGTH_SHORT).show();
Log.v("glide", "Error loading image", e);
return false; // important to return false so the error placeholder can be placed
}
#Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.into(dp);
Log
2018-11-02 19:20:08.709 31664-31664/com.example.user.myapplication W/Glide: Load failed for C:/Apache24/htdocs/app2/User Files/User Id-102/User id 102.jpg with size [200x200]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
2018-11-02 19:20:08.718 31664-31664/com.example.user.myapplication V/glide: Error loading image
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
I cannot figure out actually from where the error is occurring.

I found the solution, I wanted to load file from the localhost server of my pc and I was using pc file system reference which glide does not support but when I passed the IP address along with the file address (e.g. http://(your ip like 192....)/your localhost project folder/image.jpg) and it worked.

It seems you're using an invalid image reference. Glide can load resources from the internet (http or https) or from the device's (mobile/tablet) file system. But it seems your response contains a reference to an image file on your PC's file system.

Related

How to request again if image download failed using glide

I'm try to download multiple images from server using the Glide
here is code
for (String url : list) {
RequestOptions requestOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL);
Glide.with(this)
.asBitmap()
.load(url).addListener(new RequestListener<Bitmap>() {
#Override
public boolean onLoadFailed(#Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
Log.e("ProgressCheck", "onResourceReady: " + progress);
return false;
}
})
.apply(requestOptions)
.submit();
}
Code run perfectly but when the downloading image failed (any reason wifi disconnected or server not responding.etc) how to send the same request again??
or is there the better way download multiple images using Glide
I suggest you to make a separate method of loading image via glide.
Here is the pseudo code
private void loadImage(String URL){
// Your Glide code
//Inside onLoadFailed call loadImage() again.
//For number of attempts you can maintain one int and increment that on every attempt.
}
If error or fallback strategies are not useful to you, then in 4.3.0 version you can starting a new request on failure:
Glide.with(fragment)
.load(url)
.error(
Glide.with(fragment)
.load(url))
.into(imageView);
Learn more at https://bumptech.github.io/glide/doc/options.html#starting-a-new-request-on-failure

Failed to load resource without exception detail

I use Glide to load a URL of image to image view, like this:
RequestOptions requestOptions = new RequestOptions().placeholder(R.drawable.image_place_holder).error(R.drawable.image_place_holder);
Glide.with(imageView.getContext())
.load(url)
.listener(new RequestListener() {
#Override
public boolean onLoadFailed(#Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
// Log the GlideException here (locally or with a remote logging framework):
Log.e(TAG, "Load failed", e);
e.printStackTrace();
// You can also log the individual causes:
for (Throwable t : e.getRootCauses()) {
Log.e(TAG, "Caused by", t);
}
// Or, to log all root causes locally, you can use the built in helper method:
e.logRootCauses(TAG);
return false; // Allow calling onLoadFailed on the Target.
}
#Override
public boolean onResourceReady(Object resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.apply(requestOptions)
.into(imageView);
But Glide throw an exception in onLoadFailed() and show the place holder image instead:
W/Glide: Load failed for https://abc.xyz/image.png with size [736x388]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
TAG : Load failed
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
You can see the exception has no causes, and can't print stack trace.
I try to use the Picasso library or change to another URL, it works!
But I can't understand what happen with the image link. Can you explain this problem here?

Glide for Android - Url request is not sent out, no exception

Glide Version: 4.7.1
Integration libraries: okhttp 4.7.1
I am trying to access and image (PNG) on a server but the request is not even sent. Can the URL formation crash the lib without an error message ? Or maybe it's sent but there is neither a failure response in the Request Listener nor a success.
How can i trace the problem ?
I have tried following the execution chain but i can only see the preparation of the request.
I monitor the network with Charles and i can't see the request sent out
I am using a basic GlideApp module call
GlideApp.with(mApplicationContext).load(url).dontAnimate().listener(new RequestListener<Drawable>() {
#Override
public boolean onLoadFailed(#Nullable final GlideException e, final Object model, final Target<Drawable> target, final boolean isFirstResource) {
// Nothing arrives here
return false;
}
#Override
public boolean onResourceReady(final Drawable resource, final Object model, final Target<Drawable> target, final DataSource dataSource, final boolean isFirstResource) {
// Nothing arrives here
return false;
}
}).into(imageView);
Thanks
OK i figured it out.
I was passing an newly created ImageView in code that i was using to store the returned image temporarily. This had no dimensions.
This worked fine with the Picasso library, but stopped working when i changed to Glide. So passing a real ImageView that is visible in a layout, works.
Picasso had another issue with PNG's which is why i switched.

Suddenly Glide is failing to get image from url

Thanks for viewing my question here.
I am using Glide to fetch image from Firebase storage, basically i am using url to get the image from storage. First day it was working fine but suddenly it stopped fetching image. i did not touch the code. I have checked many answer but still i could not fix the issue. Please let me know where i am doing mistake.
This is gradle app file.
compile 'com.github.bumptech.glide:glide:3.8.0'
compile 'com.android.support:support-v4:23.4.0'
This is the Glide code i use in my Adapter java file
Glide.with(context).load(mproduct.get(position).getUrl()).into(viewHolder.pic);
Internet permission is there
<uses-permission android:name="android.permission.INTERNET" />
If it is not loading an image, there must be an error!
Check out the reason using listener:-
Glide.with(context)
.load(mproduct.get(position).getUrl())
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
// Here you will get the cause of error...
return true;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
// do something
return true;
}
})
.into(viewHolder.pic);
Please try with Piccaso
You can try below code..
Picasso.with(getApplicationContext()).load(mproduct.get(position).getUrl()).error(R.drawable.demo_image).into(viewHolder.pic);
dont forget to add dependency for Piccasso.

Downloading images from Cloudinary in Android

I'm trying to figure out what the optimal workflow would be for an image transformation process in which a transformed image is again uploaded to another API.
According to Cloudinary (http://cloudinary.com/documentation/image_transformations#resizing_and_cropping_images), I can access uploaded images with the following kind of URL structure and also simultaneously transform them: http://res.cloudinary.com/demo/image/upload/w_200,h_100/sample.jpg.
Assuming that sample.jpg already exists in Cloudinary, the provided link will fetch it with a image resize transformation already applied.
Can I simply provide this link to Picasso and turn it into a Bitmap?
Picasso.with(this)
.load("http://res.cloudinary.com/demo/image/upload/w_200,h_100/sample.jpg")
.into(new Target() {
#Override
public void onBitmapLoaded (final Bitmap bitmap, Picasso.LoadedFrom from){
/* Save the bitmap or do something with it here */
UploadBitmap(bitmap);
}
});
Sorry, don't really know how to do it with Picasso, but with Glide you can do the following
Glide.with(this).load("path").asBitmap().listener(new RequestListener<String, Bitmap>() {
#Override
public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
}).into(500/*output width*/,500/*output height*/);
And yes, buy specifying w and h in path you can manipulate image scaling

Categories

Resources