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!

Zipped attachments - Mime Type help

843830Dec 21 2004 — edited Dec 28 2004
The solution seems to be in the mime type settings for the FileDataSource. I have added a MimetypesFileMap into the code and added "application/zip zip" as a MimeType. Then associated that FileTypeMap with the datasource, but the result is still the same.

The code is :

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Create Multipart
Multipart multipart = new MimeMultipart();

// Add part one
multipart.addBodyPart(mbp1);

// Create second body part
            MimeBodyPart mbp2;
            
            // Third part is list of attached files in error
            MimeBodyPart mbp3;
            
            FileDataSource fds;
            
            /* If zipped requested, send all checked files to be zipped
            * otherwise attach all the checked files */
            if (zip.equals("1")) {
                
                MimetypesFileTypeMap mftm = new MimetypesFileTypeMap();
                mftm.addMimeTypes("application/zip zip");
                //mftm.addMimeTypes("application/x-zip-compressed zip");
                                            
                File zipped = new File(RicohZip.ZipUpFiles(checkedFiles));
                // Create second body part
                mbp2 = new MimeBodyPart();
                                                  
                // Add the zipped file to the FileDataSource
                fds = new FileDataSource(zipped); 

                // set the mime types
                fds.setFileTypeMap(mftm);  
                               
                // Set the data handler to the attachment
                mbp2.setDataHandler(new DataHandler(fds));
                
                // Set the filename
                mbp2.setFileName(fds.getName());
                mbp2.setText("\n");
                // Add part to multipart
                multipart.addBodyPart(mbp2);
            } 
            // Put parts in message
            message.setContent(multipart);

            // Send the message
            Transport.send(message);
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 25 2005
Added on Dec 21 2004
2 comments
500 views