Reid Rivenburgh
Reid Rivenburgh

Reputation: 403

How do you extract data associated with an image that is an attachment to a Notes RichTextItem?

I've seen things that skirt around this question, but nothing that answers it directly.

I have a RichTextItem in a document that contains an attached image. If I look at the document properties for the field, it says:

Data Type: MIME Part
Data Length: 7615 bytes
...
"Content-Transfer-Encoding: binary
Content-Type: image/jpeg

then a bit of binary data. How can I extract that data in server-side javascript so that I can use it in the value of an image control? In other words, I want the data corresponding to that image to appear in the following so that it renders in the web browser:

<xp:image><xp:this.value><![CDATA[#{javascript:"data:image/jpeg;base64,<DATA HERE>

Can this be done? I've tried all sorts of things but to no avail.

Thanks, Reid

Upvotes: 0

Views: 175

Answers (1)

stwissel
stwissel

Reputation: 20384

There a several approaches you can play with.

  • The "cheat" way: use ....nsf/0/unid/RTItemName?OpenField in a dojo panel as its source. (see here. It would open the whole RichText.
  • Eventually you need OpenElement instead - can directly address an attachment
  • Last not least, since your field isn't actually RichText, but MIME, you can use the Notes MIME classes to get to the content and render it base64. The mime classes allow to get the data as stream as well as provide methods to then encode it, so you don't need an extra encoder class

Hope that helps

Upvotes: 2

Related Questions