java - Control what DataContentHandler to use for a MimeMessage attachment? -
i creating attachment mimemessage
tiff image byte array.
bytearrayoutputstream out = new bytearrayoutputstream(); mimebodypart body = new mimebodypart(); body.setcontent(tiffbytearray, "image/tiff"); body.setdisposition("attachment"); body.setfilename(filename); mimemultipart multipart = new mimemultipart(); multipart.addbodypart(body); mimemessage message = new mimemessage(session.getdefaultinstance(system.getproperties())); message.setcontent(multipart); message.writeto(out); string mimecontent = out.tostring();
this works. image converted base64 string in message. however, @ point on system occurs , piece of code starts using com.sun.xml.internal.messaging.saaj.soap.imagedatacontenthandler
. particular converted expects java.awt.image
object opposed byte array (relevant source). following error:
unable encode image stream imagedatacontenthandler requires image object, given object of type class [b
i can see can set javax.activation.datahandler
on javax.mail.internet.mimemessage
, in datahandler
can set javax.activation.datacontenthandlerfactory
, i'm not sure set to.
is there way force byte array converted base64 encoded string regardless of mime type?
javax.mail
provides datasource
implementation bytes can explicitly use.
bytearraydatasource datasource = new bytearraydatasource(tiffbytearray, "image/tiff"); datahandler bytedatahandler = new datahandler(datasource); body.setdatahandler(bytedatahandler); body.setdisposition("attachment"); body.setfilename(filename);
Comments
Post a Comment