My Glide doest not display image sent from my server

633 views
Skip to first unread message

raxis...@gmail.com

unread,
Aug 31, 2015, 4:41:22 AM8/31/15
to Glide

Hi, sorry for my bad english in advance :p

I currently using Glide 3.6.1, AndroidStudio 1.2.2 and NetBean 8.0.2

I created server based on java and client based on android (using Glide).
my Glide work fine if i get an image from URL another website, but it display nothing when i get image from my server.
So i tried to access again with browser and it work fine. the browser display a image that i need.
the server send same response to browser and glide.

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();
                respond
= "\r\n";
                output
.write((respond).getBytes());
                output
.flush();

I have to hard code the response because i use socket as my output not http handler, because my server need to handle another request.
whether Glide need additional parameter? why image doesn't appear?

my another question
is there any way to show exception?
i mean i just use glide like this:
Glide.with(context).load(ImageURL).override(50,50).into(holder.image);
i dont know, if my glide return exception or not, i mean maybe the glide return some exception when receive respond from my server but how i can handle it?



Róbert Papp

unread,
Aug 31, 2015, 5:15:47 AM8/31/15
to raxis...@gmail.com, Glide
i tried to access again with browser and it work fine 
Is your server running on your computer or on the internet? On the computer or on the phone browser? Does your imageurl contain "localhost"?

When I had similar problems it meant that I needed to expose the webserver running on my computer on the internet via the public IP (may need router configuration to port-forward) or on the local network via local IP.
In both cases http://localhost:1234/image.jpg will try to access port 1234 on the phone and request the image (same is true for 127.0.0.1). Check your IPv4 Address in command line via ipconfig on Windows or inet addr via ifconfig on Unix. Only start testing with Glide once the image can be loaded in a browser on the phone.

if my glide return exception or not
If I'm wrong about the above and you already use the correct IP or machine name read this: https://github.com/bumptech/glide/wiki/Debugging-and-Error-Handling and I suggest you add .listener(new RequestListener...)before into and log the arguments to see what's going on.

Other possible problems
You also shouldn't lie about the contents of the stream, compare: "Content-Type: image/png\r\n" and write(bi,"JPG",output)
You're also writing the HTTP response header after the image contents, why?
You can increase the response time if you open a FileInputStream to imageLocation and copy the stream over to output. Of course this doesn't work if you want to modify the bitmap in memory before compressing it with JPG to the output.

Hope this helps,
+Robi

--
You received this message because you are subscribed to the Google Groups "Glide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glidelibrary...@googlegroups.com.
To post to this group, send email to glidel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glidelibrary/dd9423d9-449f-48cf-bf1e-e737ff7e13b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

raxis...@gmail.com

unread,
Aug 31, 2015, 10:23:08 PM8/31/15
to Glide, raxis...@gmail.com
Hi Robert, thanks for your reply,

my Glide finally can get an image from my server, thanks for your suggestion.
so i remove my http header , and this is working code :
respond = "HTTP/1.1 200 OK\r\n";
respond
+= "Date: " + LocalDateTime.now() + "\r\n";

respond
+= "\r\n";
output
.write((respond).getBytes());
output
.flush();

"You're also writing the HTTP response header after the image contents, why?"
Yes, but i send my HTTP response first then my image.

Thank you

Róbert Papp

unread,
Sep 1, 2015, 4:41:01 AM9/1/15
to Ronny Sulistio, Glide

Hi, glad it worked out!

>> You're also writing the HTTP response header after the image contents, why?

> Yes, but i send my HTTP response first then my image.

Sorry, yes, I see it now, you repurposed the local variable respond:

> respond = "\r\n";
> output.write((respond).getBytes());

This is what confused me, but still, I don't think you need a new line after the contents, because the image is binary.

+Robi

--
You received this message because you are subscribed to the Google Groups "Glide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glidelibrary...@googlegroups.com.
To post to this group, send email to glidel...@googlegroups.com.

raxis...@gmail.com

unread,
Sep 5, 2015, 1:12:11 AM9/5/15
to Glide, raxis...@gmail.com

> respond = "\r\n";
> output.write((respond).getBytes());

This is what confused me, but still, I don't think you need a new line after the contents, because the image is binary.

+Robi


aahh i see, ok i will remove it, thank you
Reply all
Reply to author
Forward
0 new messages