Reputation: 179
I'm using Glide
as my image loader to client.
and I create my own server from java.
My server's code:
File f = new File(imageLocation);
try{
bi = ImageIO.read(f);
}catch (Exception e){
f = new File(imageLocation);
bi = ImageIO.read(f);
}
respond = "HTTP/1.1 200 OK\r\n";
respond += "Date: " + LocalDateTime.now() + "\r\n";
respond += "Content-Type: image/png\r\n";
respond += "Content-Length: " + f.length() + "\r\n";
respond += "Connection: keep-alive\r\n";
respond += "\r\n";
output.write((respond).getBytes());
output.flush();
ImageIO.write(bi,"JPG",output);
output.flush();
I tested from my browser and it work fine,
but when I call using Glide
from android, no image displayed
Upvotes: 0
Views: 312
Reputation: 46470
The Content-Length
may confuse glide, because you're lying about it, the original File length may not be the same as the re-encoded JPG output.
You're also lying about the Content-Type
because it's a JPG, not a PNG as you state it, however I think Glide would ignore that.
I think it would be better to just send the imageLocation
's bytes to the output
, then the Content-Length
can be predicted simply.
i still trying to figure how to get any exception from Glide if exist
As stated in the Google Groups discussion, read https://github.com/bumptech/glide/wiki/Debugging-and-Error-Handling and I suggest you add .listener(new RequestListener...)
before .into(imageView)
and log the arguments to see what's going on.
Upvotes: 1