title: How do you access an attachment stored as MIME Part?
body: <p>It seems to me there are two ways to store an attachment in a NotesDocument.</p>
  
  <p>Either as a RichTextField or as a "MIME Part".</p>
  
  <p>If they are stored as RichText you can do stuff like: </p>
  
  <p>document.getAttachment(fileName)</p>
  
  <p>That does not seem to work for an attachment stored as a MIME Part.  See screenshot
  <img src="https://i.stack.imgur.com/KkZ2k.jpg" alt="enter image description here"></p>
  
  <p>I have thousands of documents like this in the backend. This is NOT a UI issue where I need to use the file Download control of XPages.</p>
  
  <p>Each document as only 1 attachment.  An Image. A JPG file.  I have 3 databases for different sizes.  Original, Large, and Small.  Originally I created everything from documents that had the attachment stored as RichText.  But my code saved them as MIME Part. that's just what it did.  Not really my intent.</p>
  
  <p>What happened is I lost some of my "Small" pictures so I need to rebuild them from the Original pictures that are now stored as MIME Part.  So my ultimate goal is to get it from the NotesDocument into a Java Buffered Image.</p>
  
  <p>I think I have the code to do what I want but I just "simply" can't figure out how to get the attachment off the document and then into a Java Buffered Image.</p>
  
  <p>Below is some rough code I'm working with.  My goal is to pass in the document with the original picture.  I already have the fileName because I stored that out in metaData. But I don't know how to get that from the document itself.  And I'm passing in "Small" to create the Small image.</p>
  
  <p>I think I just don't know how to work with attachments stored in this manner.  </p>
  
  <p>Any ideas/advice would be appreciated!  Thanks!!!</p>
  
  <pre><code>public Document processImage(Document inputDoc, String fileName, String size) throws IOException {
      // fileName is the name of the attachment on the document
      // The goal is to return a NEW BLANK document with the image on it
      // The Calling code can then deal with keys and meta data.
  
  // size is "Original", "Large" or "Small"
  System.out.println("Processing Image,  Size = " + size);
  //System.out.println("Filename = " + fileName);
  
  boolean result = false;
  
  Session session = Factory.getSession();
  Database db = session.getCurrentDatabase();
  session.setConvertMime(true);
  
  BufferedImage img;
  BufferedImage convertedImage = null;  // the output image
  
  EmbeddedObject image = null;
  InputStream imageStream = null;
  
  int currentSize = 0;
  int newWidth = 0;
  String currentName = "";
  
  
  try {
      // Get the Embedded Object
      image = inputDoc.getAttachment(fileName);
      System.out.println("Input Form : " + inputDoc.getItemValueString("form"));
  
      if (null == image) {
          System.out.println("ALERT - IMAGE IS NULL");
      }
  
  
      currentSize = image.getFileSize();
      currentName = image.getName();
  
  
      // Get a Stream of the Imahe
      imageStream = image.getInputStream();
      img = ImageIO.read(imageStream);  // this is the buffered image we'll work with
      imageStream.close();
  
  
      Document newDoc = db.createDocument();
      // Remember this is a BLANK document. The calling code needs to set the form
  
  
      if ("original".equalsIgnoreCase(size)) {
          this.attachImage(newDoc, img, fileName, "JPG");
          return newDoc;
      }
  
      if ("Large".equalsIgnoreCase(size)) {
          // Now we need to convert the LARGE image
          // We're assuming FIXED HEIGHT of 600px
          newWidth = this.getNewWidth(img.getHeight(), img.getWidth(), 600);
          convertedImage = this.getScaledInstance(img, newWidth, 600, false);
          this.attachImage(newDoc, img, fileName, "JPG");
          return newDoc;
  
      }
  
      if ("Small".equalsIgnoreCase(size)) {
          System.out.println("converting Small");
          newWidth = this.getNewWidth(img.getHeight(), img.getWidth(), 240);
          convertedImage = this.getScaledInstance(img, newWidth, 240, false);
          this.attachImage(newDoc, img, fileName, "JPG");
          System.out.println("End Converting Small");
          return newDoc;
  
      }
  
      return newDoc;
  
  
  
  
  } catch (Exception e) {
      // HANDLE EXCEPTION HERE
      // SAMLPLE WRITE TO LOG.NSF
      System.out.println("****************");
      System.out.println("EXCEPTION IN processImage()");
      System.out.println("****************");
      System.out.println("picName: " + fileName);
      e.printStackTrace();
      return null;
  
  } finally {
      if (null != imageStream) {
          imageStream.close();
      }
      if (null != image) {
          LibraryUtils.incinerate(image);
      }
  
  }
  </code></pre>
  
  <p>}</p>