Skip to main content
Solved

Plugin: spawn attachment preview

  • February 24, 2025
  • 2 replies
  • 63 views

NPdevs
Forum|alt.badge.img+2

Is there a way to preview a message attachment from the Sidebar plugin, for example using the plugin SDK downloadAttachment()?

I am currently only getting a File object returned from Front.downloadAttachment('msg_xxx', 'fil_xxx') with the following properties:


lastModified:  1740416909060
lastModifiedDate:  Mon Feb 24 2025 18:08:29 GMT+0100 (Central European Standard Time) {}
name: "fd880b5930634b94bfa961a2b3815db2.jpg"
size:  293622
type:  "image/jpeg"
webkitRelativePath: ""

Best answer by NPdevs

This opens an attachment in a new window/tab.

Front.downloadAttachment(message.id, attachment.id)
.then(blob => {
const fileURL = URL.createObjectURL(blob);
window.open(fileURL, '_blank'); // Opens in a new tab
})
.catch(error => {
console.error('Error fetching attachment:', error);
});

 

2 replies

jason
Forum|alt.badge.img+8
  • Fronteer
  • February 24, 2025

That SDK method is what you’ll want to use. It delivers the raw attachment content, so you can present it using whatever method you like as a preview. 

Front does not currently provide any built-in tooling to render a file preview, so you can use whatever tool you’re already familiar with to render your preview. 


NPdevs
Forum|alt.badge.img+2
  • Author
  • Helper
  • Answer
  • February 24, 2025

This opens an attachment in a new window/tab.

Front.downloadAttachment(message.id, attachment.id)
.then(blob => {
const fileURL = URL.createObjectURL(blob);
window.open(fileURL, '_blank'); // Opens in a new tab
})
.catch(error => {
console.error('Error fetching attachment:', error);
});