0

I am trying to write an email client that reads email files that have been sent to an S3 bucket via AWS SES and displays those email files in a browser like other email clients do. One of the tasks that I am grappling with is how to display the attachments which I get in the form of a buffer. For example, for a pdf attachment, I get a data buffer of contentType "application/pdf". Is there a way to embed this data stream into a HTML field such that it shows up as a properly formatted pdf document?

here is screen shot of what I have at the client page level:
enter image description here

Joundill
  • 6,828
  • 12
  • 36
  • 50
david barg
  • 181
  • 1
  • 9
  • I'm not familiar with the amazon part, but if the Browser has a PDF reader you could just create a link like `View PDF`. If you want to view it in the same page you could use an ``, but that won't work on Chrome mobile, so what's the point. – StackSlave Feb 04 '21 at 00:34
  • thanks @StackSlave, but there is no "pdflocation"...the buffer is generated "on the fly" from the eml file using Mailparser (https://www.npmjs.com/package/mailparser). I never actually have a pdf file per se -- only its representation as this data buffer extracted from the larger eml file. – david barg Feb 04 '21 at 00:58
  • 1
    If it's a blob then `document.querySelector('a').href = URL.createObjectURL(blob);`. Note that will just get the first `` on the page. You may want to use a different getter. – StackSlave Feb 04 '21 at 01:12
  • ps., at this point I am NOT necessarily looking for a solution that will also work on a mobile platform. For now I am focusing only on a web/html client. – david barg Feb 04 '21 at 01:14
  • @StackSlave Thanks, but it is not a blob and I don't know how to turn it into a blob. :( – david barg Feb 04 '21 at 12:34
  • I am thinking that this might be relevant to answering my question. Any thoughts from out there? https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs – david barg Feb 04 '21 at 19:40
  • this is also relevant: https://stackoverflow.com/questions/2805330/opening-pdf-string-in-new-window-with-javascript – david barg Feb 05 '21 at 01:35
  • ???? It looks like it could be an ArrayBufffer? Try `document.querySelector('a').href = URL.createObjectURL(new Blob([globalVal.attachments[0]], {type:'application/pdf'}));` or some variation. Good luck! – StackSlave Feb 05 '21 at 02:27

0 Answers0