public static void main(String[] args) { String file = "fsd.png"; String type = MimeTypesUtil.getMimeTypeFromFilename(file); System.out.println(type); }
public static void main(String[] args) { String file = "fsd.png"; String type = MimeTypesUtil.getMimeTypeFromFilename(file); System.out.println(type); }
/** * Add attachments to a multipart message * * @param multipart Multipart message * @param attachments List of attachments */ public MimeBodyPart createAttachmentBodyPart(Attachment attachment, XWikiContext context) throws XWikiException, IOException, MessagingException { String name = attachment.getFilename(); byte[] stream = attachment.getContent(); File temp = File.createTempFile("tmpfile", ".tmp"); FileOutputStream fos = new FileOutputStream(temp); fos.write(stream); fos.close(); DataSource source = new FileDataSource(temp); MimeBodyPart part = new MimeBodyPart(); String mimeType = MimeTypesUtil.getMimeTypeFromFilename(name); part.setDataHandler(new DataHandler(source)); part.setHeader("Content-Type", mimeType); part.setFileName(name); part.setContentID("<" + name + ">"); part.setDisposition("inline"); temp.deleteOnExit(); return part; }
/** * Add attachments to a multipart message * * @param attachment the attachment to create the body part for. * @param context the XWiki context. * @return the body part for the given attachment. */ public MimeBodyPart createAttachmentBodyPart(Attachment attachment, XWikiContext context) throws XWikiException, IOException, MessagingException { String name = attachment.getFilename(); byte[] stream = attachment.getContent(); File temp = new TemporaryFile(File.createTempFile("tmpfile", ".tmp")); FileOutputStream fos = new FileOutputStream(temp); fos.write(stream); fos.close(); DataSource source = new FileDataSource(temp); MimeBodyPart part = new MimeBodyPart(); String mimeType = MimeTypesUtil.getMimeTypeFromFilename(name); part.setDataHandler(new DataHandler(source)); part.setHeader("Content-Type", mimeType); part.setFileName(name); part.setContentID("<" + name + ">"); part.setDisposition("inline"); return part; }