# Conversion from string to media

**URL:** <https://forum.servoy.com/t/conversion-from-string-to-media/11258>\
**Category:** Classic Servoy\
**Created:** [October 9, 2009, 7:47am UTC](https://forum.servoy.com/t/conversion-from-string-to-media/11258 "2009-10-09T07:47:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![michel](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@michel](https://forum.servoy.com/u/michel)\
**Post date:** [October 9, 2009, 7:47am UTC](https://forum.servoy.com/t/conversion-from-string-to-media/11258/1 "2009-10-09T07:47:59Z")

</div>

Is it possible to put a string directly (using some function) in a media-field instead of first generating a temporary textfile and then read it binary?

```auto
_my_string = "bladiebla"
tempFile = plugins.file.createTempFile('memo','.tmp');	
success = plugins.file.writeTXTFile(tempFile, _my_string, 'ISO8859_1')
foundset.memo_field = plugins.file.readFile(tempFile.getPath())

```

We want this for conversion because our foxpro database-driver treats the memo-fields as a string.

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [October 9, 2009, 9:18am UTC](https://forum.servoy.com/t/conversion-from-string-to-media/11258/2 "2009-10-09T09:18:48Z")

</div>

why MEDIA?  
you can also create TEXT columns instead of varchar.  
just create a TEXT column in Servoy (with very large number) it will automaticly create a TEXT column for you in the DB (in case of Sybase)

---

<div class="post-metadata">

**Author:** ![michel](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@michel](https://forum.servoy.com/u/michel)\
**Post date:** [October 9, 2009, 9:58am UTC](https://forum.servoy.com/t/conversion-from-string-to-media/11258/3 "2009-10-09T09:58:25Z")

</div>

Because in the foxpro table this field can also contain binary data (like an image or a word document), the foxpro driver presents this as a string to me. But in servoy and the sybase database I want store this data in a media-field.

---

<div class="post-metadata">

**Author:** ![Jan\_Blok](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Jan\_Blok](https://forum.servoy.com/u/Jan_Blok)\
**Post date:** [October 12, 2009, 2:08pm UTC](https://forum.servoy.com/t/conversion-from-string-to-media/11258/4 "2009-10-12T14:08:43Z")

</div>

There are major complications when storing text in binary, to be able to store as binary you have to use character encodings … you don’t want to get into character encoding problems.  
Do keep text as text and leave char encoding to Java/database diriver and make sure database is running in UTF (as Servoy by default does)

---

<div class="post-metadata">

**Author:** ![michel](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@michel](https://forum.servoy.com/u/michel)\
**Post date:** [October 13, 2009, 12:55pm UTC](https://forum.servoy.com/t/conversion-from-string-to-media/11258/5 "2009-10-13T12:55:19Z")

</div>

Not that I want it, but I cannot tell the databasedriver (HXTT) to see the foxpro MEMO-field as a servoy MEDIA-field, instead of that it is treated as a TEXT(0) field. So in order to do my conversion from foxpro to sybase I have to do conversion from string to media…  
In the samplecode the conversion is done correctly, but for performance reasons I don’t want to do this using a temporary file.

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [October 13, 2009, 1:11pm UTC](https://forum.servoy.com/t/conversion-from-string-to-media/11258/6 "2009-10-13T13:11:13Z")

</div>

Michel,

try this: var doc = new java.lang.String(documents\_to\_templates.template)

in this case template is MEDIA field, which I get an RTF document. (TEXT)

Hope this helps

---

<div class="post-metadata">

**Author:** ![Jan\_Blok](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Jan\_Blok](https://forum.servoy.com/u/Jan_Blok)\
**Post date:** [October 13, 2009, 1:43pm UTC](https://forum.servoy.com/t/conversion-from-string-to-media/11258/7 "2009-10-13T13:43:10Z")

</div>

Both last posts (temp file and java String workarrounds) assume the binary format of the string being encoded in default (OS specific) charset…this is very likly NOT the case, leading to character conversion problems!!
