createBinaryAttachment from something stored in Media?

Hi, I’m trying to build a non-html email with a logo attached. My logo is stored in Media.

Is it possible to create a binary attachment, like

plugins.mail.createBinaryAttachment('logo.gif','media:///logo.gif')

I can’t get this to work…

swingman:
Hi, I’m trying to build a non-html email with a logo attached. My logo is stored in Media.

Is it possible to create a binary attachment, like

plugins.mail.createBinaryAttachment('logo.gif','media:///logo.gif')

I can’t get this to work…

Even if you put the binary in a var and load the var?

HI Riccardo,

How do I load ‘media:///logo.gif’ into a variable?

C.

swingman:
HI Riccardo,

How do I load ‘media:///logo.gif’ into a variable?

C.

To be honest, I use another method:

var attach = plugins.mail.createBinaryAttachment( globals.gAttachName,  globals.gAttachFile)

This should also work for you.

Hi Riccardo,

So you would store the logo in a field in the database – I have a table for the company settings, so I could put a logo there, no problem.

I was just curious to know whether there is a way of reading a graphic from the Media store in Servoy without having to resort to querying the relevant table in the repository directly using SQL.

Servoyans? Any ideas?

Hi Christian,

Not sure if this is a solution … however, there is a function under the http plugin as follows:

//Get media(binary data) such as images in a variable
var image_byte_array = plugins.http.getMediaData('http://www.cnn.com/cnn.gif');

I wonder whether this would give you what you need to then attach to your mail ?

Cheers
Harry

Hi Harry,

the problem is that the graphic is in Servoy’s media store, so I’d be surprised if the http plugin would be able to get at it…

Hi Christian,

The following does seem to work:

//Get media(binary data) such as images in a variable 
var image_array = plugins.http.getMediaData('media:///find.png');

it loads an array of bytes into the variable - but what you do with it then is not my strength :(

Also you have this:

//Get a javascript image/resource object for the given file/bytearray/bean/applet/form_element
var image = plugins.images.getImage('media:///find.png');//loads the image

Which returns a JS image object of the target image in the media library
But again, wouldn’t know what to do with it from there either :lol:

All in all, I am not much use here except to offer options for you to test :oops:

Hope something works for you

Cheers
Harry

swingman:
the problem is that the graphic is in Servoy’s media store, so I’d be surprised if the http plugin would be able to get at it…

Another way to grab an image from Servoy’s media library is by using the getThumbnailJPGImage() function. First assign any media resources to named objects on a form and then apply the function to an object to pop the image of it into a variable. Modify the following code to attach the variable as an email attachement instead of saving out to a file:

//save an image of a resource item
//in the Servoy media library to a file

var objName = "btn_sortAsc"

var media = elements[objName].getThumbnailJPGImage()

var file = plugins.file.showFileSaveDialog()

plugins.file.writeFile(file,media)

So many options after all :) That’s Servoy for you.