0

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

Per Henrik Lausten
  • 21,331
  • 3
  • 29
  • 76
Reid Rivenburgh
  • 373
  • 1
  • 9

1 Answers1

2

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

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • Thank you. I'm currently doing your first approach in some cases. Unfortunately, I'm not able to scale my images using CSS when I do that (separate question, perhaps), so I'm trying to use an image. I will look into #2. #3 sounds like what I've been trying to do, and in theory it seems like it should work, but I haven't been able to put the right pieces together to get it to work. – Reid Rivenburgh Oct 31 '16 at 14:26
  • 2
    Maybe this answer can help you get a base64 encoding of images: http://stackoverflow.com/a/19328276/785061 – Per Henrik Lausten Oct 31 '16 at 20:15
  • Thanks, Per. That does indeed look helpful! – Reid Rivenburgh Nov 01 '16 at 15:02
  • Well, that approach didn't get me far.... It seems the getEmbeddedImageStream call returns null in my situation. – Reid Rivenburgh Nov 02 '16 at 00:13
  • Sadly, I cannot get stwissel's second approach (with OpenElement) to work, either. Concrete examples (URLs and/or code) gladly accepted! – Reid Rivenburgh Nov 02 '16 at 16:34