How can I send an image on the web in an XMPP (Jabber) message?
Asked Answered
B

3

13

For the XMPP interface for the Stack Overflow chat, I am currently taking the HTML of the chat messages and converting to valid XML, and setting that as the html child element of the XMPP message object. In my Mac OS X jabber client this was working great! It meant that when users in the SO chat posted a oneboxed image, the image would show up in my XMPP client (Adium for OS X):

My Mind Is Blown

However I just updated Adium to the latest version and apparently they considered what I was doing to be a security hole and against XMPP specs, and changed that behavior. Their reasoning was that XMPP should not reveal your Ip address, and to fetch an image over HTTP would reveal my IP address.

So now the chats are imageless over XMPP. How can I make images work over XMPP? Should my XMPP component download the images and embed them into the <Message> stanzas? Can the images be proxied through the XMPP server? Or is this an impossibility?

Boatload answered 16/11, 2010 at 20:21 Comment(2)
Seriously, I don't understand these people that think an IP is private data you should secure. If you can be attacked just by knowing your IP, you're f*ed anyway.Hemangioma
I agree @Camilo. And it seriously crippled what was previously an awesome interface to chat!Boatload
L
6

Adium, iChat and Pidgin all support XEP-0231, which allows you to send the provide binary data, including images to this purpose. Basically, it allows you to specify a unique identifier as the source for an image, and then the other client can decide if he wants to request the data in a <iq> request.

I've been working with this in python's Twisted, but meeting with some frustration. I do know that Adium and iChat at least use it to request the data.

Latoyalatoye answered 7/10, 2011 at 22:49 Comment(2)
Wow that looks great, and may be just the incentive I needed to pick the StackExchange XMPP Chat bridge project back up!Boatload
Let me know if you do -- as far as I can tell, I've implemented the spec, but Google Talk is apparently very picky and/or confusing about its error messages. I'd be interested to help / see how it pans out!Latoyalatoye
I
4

Try embedding it in a data: uri, like <img src="data:image/png;base64,VGhlIGltYWdlIGRhdGEgZ29lcyBoZXJlCg==" alt="some text" />

Interventionist answered 16/11, 2010 at 20:44 Comment(1)
That was a great idea. I should have mentioned that I tried that, but is displays as a broken image in Adium :-(Boatload
H
1

Just an idea...

What about parsing the image URL's, downloading the images, putting them into a temp folder with filenames representative of the original URLs (the filename could be a hash of the original URL) and substituting the original URLs in the messages for these file URLs?

Another idea... having a local server that fetches the real URLs?

Hemangioma answered 17/11, 2010 at 3:3 Comment(2)
The problem is, the XMPP bridge runs on a remote server, not on my local machine. So a file:// URL wouldn't get me anywhere. I could try your idea but instead of file://, serving them from an http:// URL where the domain of the URL is the same as the XMPP server, but, will that work?Boatload
I see. Well, in theory yes - you could set something quick cURL in another port, I guess. Having that said I'm not a server-side guy.Hemangioma

© 2022 - 2024 — McMap. All rights reserved.