URL image fetch

141 views
Skip to first unread message

witiProg

unread,
Aug 9, 2010, 11:43:44 PM8/9/10
to Google App Engine
Hi every body
Sorry for my english.
I'm tryn to fetch an image from url, and then send it via mail;
this is my code:

String url = "http://www.google.co.ve/images/firefox/
globe_getinvolved.png"
String contenttype ;

URL myurl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) myurl.openConnection();
contenttype = conn.getContentType();
Object image = conn.getContent();
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("XX...@gmail.com","Admin"));
msg.addRecipient(Message.RecipientType.TO,"XX...@gmail.com");
msg.setSubject(url);
MimeBodyPart ad = new MimeBodyPart();
ByteArrayDataSource src = new
ByteArrayDataSource((InputStream)image,contenttype);
ad.setDataHandler(new DataHandler(src));
Multipart mp = new MimeMultipart();
mp.addBodyPart(ad);
msg.setContent(mp);
Transport.send(msg);


The problem is when i do the cast to the object
'image' (InputStream)image ; How can i do to convert the result of the
conn.getContent(); to an InputStream or to a byte[].
Thanks

Ikai L (Google)

unread,
Aug 10, 2010, 1:40:51 PM8/10/10
to google-a...@googlegroups.com
There are a few threads about forwarding emails with attachments here:



The code in those posts *should* still be working. We made a change to how inbound emails were handled, but I don't believe it's broken any of that code.


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.




--
Ikai Lan 
Developer Programs Engineer, Google App Engine
Reply all
Reply to author
Forward
0 new messages