Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How do you set Content-Transfer-Encoding:base64 ?

843830Sep 9 2005 — edited Sep 9 2005
Hi,

I need to create a MultiPart Message where the Content-Type for one of the parts will be "application/octet-stream" and its Content-Transfer-Encoding will be "base64". Here's what im looking for:
--=_mixed 005FF75A85256FBE_=
Content-Type: application/octet-stream;
 name=bruton.vcf
Content-Disposition: attachment;
 filename=bruton.vcf
Content-Transfer-Encoding: base64

QkVHSU46VkNBUkQNClgtTE9UVVMtQ0hBUlNFVDpVVEYtOA0KVkVSU0lPTjozLjANClBST0RJRDot
I've tried a couple of things to get this working, first i decided to just add the headers myself in the MimeBodyPart like so:
    Message msg = new MimeMessage(session);

    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.addHeader("Content-Transfer-Encoding", "base64");
    mbp1.addHeader("Content-Type", "application/octet-stream");
    mbp1.setText("Hi");
    mbp1.setFileName("test.xml");

   // create the Multipart and add its parts to it
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    msg.setContent(mp);
But the result of this is that my headers are disregarded and the setText() method sets the Content-Type to plain text and the Encoding to 7 bit. I confirmed the headers are actually being set to the "base64" and "application/octet-stream" by commenting out the setText() but once i put in the setText() method it overrides my desired settings.

The other thing i tried was to set the Content-Type within the DataHandler Object like so:
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setDataHandler(new DataHandler("text", "application/octet-stream"));
    mbp1.setFileName("test.xml");
But this always results in :
Got Exception: javax.activation.UnsupportedDataTypeException: no object DCH for
MIME type application/octet-stream
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type appli
cation/octet-stream
I saw the javadoc for MailcapCommandMap and i found the "mailcap.default" file in my activation.jar and it already has the "application/octet-stream" value in it. So to make a long story short, i need some help.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 7 2005
Added on Sep 9 2005
4 comments
2,559 views