# createBinaryAttachment from something stored in Media?

**URL:** <https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399>\
**Category:** Classic Servoy\
**Created:** [April 25, 2007, 1:03pm UTC](https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399 "2007-04-25T13:03:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [April 25, 2007, 1:03pm UTC](https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399/1 "2007-04-25T13:03:05Z")

</div>

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

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

```

I can’t get this to work…

---

<div class="post-metadata">

**Author:** ![Riccardino](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@Riccardino](https://forum.servoy.com/u/Riccardino)\
**Post date:** [April 25, 2007, 3:39pm UTC](https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399/2 "2007-04-25T15:39:55Z")

</div>

> 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
> 
> ```auto
> 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?

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [April 25, 2007, 3:48pm UTC](https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399/3 "2007-04-25T15:48:43Z")

</div>

HI Riccardo,

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

C.

---

<div class="post-metadata">

**Author:** ![Riccardino](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@Riccardino](https://forum.servoy.com/u/Riccardino)\
**Post date:** [April 25, 2007, 6:49pm UTC](https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399/4 "2007-04-25T18:49:39Z")

</div>

> swingman:  
> HI Riccardo,
> 
> How do I load ‘media:///logo.gif’ into a variable?
> 
> C.

To be honest, I use another method:

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

```

This should also work for you.

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [April 26, 2007, 8:17am UTC](https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399/5 "2007-04-26T08:17:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Harry\_Catharell](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@Harry\_Catharell](https://forum.servoy.com/u/Harry_Catharell)\
**Post date:** [April 26, 2007, 10:52am UTC](https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399/6 "2007-04-26T10:52:32Z")

</div>

Hi Christian,

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

```auto
//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

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [April 26, 2007, 6:32pm UTC](https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399/7 "2007-04-26T18:32:00Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Harry\_Catharell](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@Harry\_Catharell](https://forum.servoy.com/u/Harry_Catharell)\
**Post date:** [April 27, 2007, 9:28am UTC](https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399/8 "2007-04-27T09:28:08Z")

</div>

Hi Christian,

The following does seem to work:

```auto
//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 ![:(]( "Sad")

Also you have this:

```auto
//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:]( "Laughing")

All in all, I am not much use here except to offer options for you to test ![:oops:]( "Embarassed")

Hope something works for you

Cheers  
Harry

---

<div class="post-metadata">

**Author:** ![david](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@david](https://forum.servoy.com/u/david)\
**Post date:** [April 27, 2007, 11:34pm UTC](https://forum.servoy.com/t/createbinaryattachment-from-something-stored-in-media/7399/9 "2007-04-27T23:34:47Z")

</div>

> 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:

```auto
//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 ![:)]( "Smile") That’s Servoy for you.
