<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: how can i read File from Database</title><link>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database</link><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I have a BLOB file in my mysql database. 
When reading, the line is a recor&lt;img alt="alt text" src="http://answers.axonivy.com/upfiles/Bildschirmfoto_2017-06-06_um_15.39.10_K1murx1.png"&gt;d and the field (blob) is an Object. 
How do I convert an object to a file data type from the ivyscript?&lt;/p&gt;
&lt;p&gt;You can see it at the attachmend.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 09 Jun 2017 05:16:35 -0400</lastBuildDate><item><title>Comment by Reto Weiss on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2692</link><description>&lt;p&gt;Hi Eugene&lt;/p&gt;
&lt;p&gt;This seems to be more a support topic than a simple Q&amp;amp;A now. Can we continue this on our Support channel? To do so please send a mail to ivy@axonivy.com.&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Reto Weiss, Axon.ivy Support&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Fri, 09 Jun 2017 05:16:35 -0400</pubDate><guid>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2692</guid></item><item><title>Comment by Eugene on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2691</link><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;thank you very much for your great support.&lt;/p&gt;
&lt;p&gt;Cast a objekt to binary is working now. 
But if I download the file (tried with text and PDF files) by using DefaultStreamedContent, I am not able to open it, because there are some special characters: ¨Ìsr'ch.ivyteam.ivy.scripting.objects.Binary[bytest[Bxpur[B¨Û¯T‡xpTestHalloTest&lt;/p&gt;
&lt;p&gt;It seems that the encoding is wrong.&lt;/p&gt;
&lt;p&gt;Best Regards,
Eugene&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Eugene</dc:creator><pubDate>Thu, 08 Jun 2017 12:59:10 -0400</pubDate><guid>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2691</guid></item><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database/2687</link><description>&lt;p&gt;Hi &lt;/p&gt;
&lt;p&gt;You can do it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Binary binary = in.Data.document.document.getField("File") as Binary;
File file = new File(in.Data.document.document.getField("Name").toString());
file.writeBinary(binary);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You first have to cast the Object returned from getField to a Binary using the &lt;code&gt;as&lt;/code&gt; operator of IvyScript&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Reto Weiss, Axon.ivy Support&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Thu, 08 Jun 2017 11:36:52 -0400</pubDate><guid>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database/2687</guid></item><item><title>Comment by Eugene on metehan's question</title><link>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2684</link><description>&lt;p&gt;We save the file over the database process element as a blob with in.file.readBinary()
Runtime log by using in.Data.document.document.getField("File").getClass().toString() give us:
class ch.ivyteam.ivy.scripting.objects.Binary
I tried this:
File file = new File(in.data.document.document.getField("Name").toString());
file.writeBinary(in.Data.document.document.getField("File"));
But I get the following error:
Method writeBinary(Object) for class file of classloader org.eclipse.osgi.internal.loader.EquinoxClassLoader@44c54463[ch.ivyteam.ivy.scripting.objects:6.6.1.201705151238(id=84)] not found.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Eugene</dc:creator><pubDate>Thu, 08 Jun 2017 08:22:31 -0400</pubDate><guid>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2684</guid></item><item><title>Comment by Reto Weiss on metehan's question</title><link>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2680</link><description>&lt;p&gt;Object can be anything. What is the type of the Object returned by getField() at runtime? You can log that by the following code:
ivy.log.info(in.Data.document.document.getField("File").getClass().toString())
If we know the type that is returned there we can find a solution to store the data to a file.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Thu, 08 Jun 2017 02:38:47 -0400</pubDate><guid>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2680</guid></item><item><title>Comment by metehan on metehan's question</title><link>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2677</link><description>&lt;p&gt;Yes the Record is the parameter. I would like to convert the object from the record into a file Type. &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">metehan</dc:creator><pubDate>Wed, 07 Jun 2017 03:34:19 -0400</pubDate><guid>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2677</guid></item><item><title>Comment by Reto Weiss on metehan's question</title><link>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2676</link><description>&lt;p&gt;Do your read the Record with the Database Step process element?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Wed, 07 Jun 2017 02:45:12 -0400</pubDate><guid>https://answers.axonivy.com/questions/2675/how-can-i-read-file-from-database#2676</guid></item></channel></rss>