Hello,

I have a BLOB file in my mysql database. When reading, the line is a recoralt textd and the field (blob) is an Object. How do I convert an object to a file data type from the ivyscript?

You can see it at the attachmend.

Thanks

asked 06.06.2017 at 09:44

metehan's gravatar image

metehan
11112
accept rate: 0%

Do your read the Record with the Database Step process element?

(07.06.2017 at 02:45) Reto Weiss ♦♦ Reto%20Weiss's gravatar image

Yes the Record is the parameter. I would like to convert the object from the record into a file Type.

(07.06.2017 at 03:34) metehan metehan's gravatar image

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.

(08.06.2017 at 02:38) Reto Weiss ♦♦ Reto%20Weiss's gravatar image

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.

(08.06.2017 at 08:22) Eugene Eugene's gravatar image

Hi

You can do it like this:

Binary binary = in.Data.document.document.getField("File") as Binary;
File file = new File(in.Data.document.document.getField("Name").toString());
file.writeBinary(binary);

You first have to cast the Object returned from getField to a Binary using the as operator of IvyScript

Regards

Reto Weiss, Axon.ivy Support

link

answered 08.06.2017 at 11:36

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
4.9k182656
accept rate: 74%

Hi,

thank you very much for your great support.

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‡xpTestHalloTest

It seems that the encoding is wrong.

Best Regards, Eugene

(08.06.2017 at 12:59) Eugene Eugene's gravatar image

Hi Eugene

This seems to be more a support topic than a simple Q&A now. Can we continue this on our Support channel? To do so please send a mail to ivy@axonivy.com.

Regards

Reto Weiss, Axon.ivy Support

(09.06.2017 at 05:16) Reto Weiss ♦♦ Reto%20Weiss's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×17

Asked: 06.06.2017 at 09:44

Seen: 872 times

Last updated: 09.06.2017 at 05:16