Loading a base64-encoded image (DataColumn, Image)

Stimulsoft Reports.JS discussion
Post Reply
thesaurus
Posts: 5
Joined: Wed Nov 02, 2016 4:36 pm

Loading a base64-encoded image (DataColumn, Image)

Post by thesaurus »

Hello,

We are trying to load an image which is stored base64-encoded in one DataSource.
The .mrt file contains the following entity (... marking the position where we tried the different possibilities listed a bit lower).

Code: Select all

            <Image1 Ref="60" type="Image" isKey="true">
              <Border>None;[31:73:125];1;DashDot;False;4;Black</Border>
              <Brush>Transparent</Brush>
              <ClientRectangle>13.6,0.4,1.8,2.4</ClientRectangle>
              <Conditions isList="true" count="0" />
              ...
              <Margins>0,0,0,0</Margins>
              <Name>Image1</Name>
              <Page isRef="3" />
              <Parent isRef="13" />
            </Image1>
The DataSource looks like this:

Code: Select all

var DataSource = {
              "DataSource": {
                            "image": base64EncodedImage,
                            "image2": "data:image/png;base64," + base64EncodedImage
            }
}
Using one of the following codes doesn't work (no error) although suggested here.

Code: Select all

<DataColumn>DataSource.image</DataColumn>
<DataColumn>DataSource.image2</DataColumn>
The following yields Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded. error.

Code: Select all

<Image>{DataSource.image}</Image>
<Image>data:image/png;base64,{DataSource.image}</Image>
<Image>{DataSource.image2}</Image>
Nonetheless, both solutions using <Image> work if the base64 string is directly embedded in the .mrt definition.

Question:
Is there a possibility to reference base64-encoded images from a DataSource?

Thank you in advance!
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Loading a base64-encoded image (DataColumn, Image)

Post by HighAley »

Hello.

Could you specify which version of our product you use?
Please, send us a sample that reproduces the issue.

Thank you.
thesaurus
Posts: 5
Joined: Wed Nov 02, 2016 4:36 pm

Re: Loading a base64-encoded image (DataColumn, Image)

Post by thesaurus »

Thank you for your reply.

We are using Stimulsoft Reports.JS 2016.2 Trial.

Please find the example attached as a zip archive.
The subfolder Demo is copied 1:1 from the Trial installation folder.

In report1.mrt please have a look at the <Image1> tag.
As described, putting the base64-encoded image there does work.
In contrast, referencing a <DataColumn> instead does not work for us.

Thank you!
Attachments
try-stimu.zip
(3.49 MiB) Downloaded 462 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Loading a base64-encoded image (DataColumn, Image)

Post by Alex K. »

Hello,

In your dictionary and registered data, column's names are different. In this case, there is a problem with showing an image.
You can try to change a name of the column with image and it should work correctly.

Also, we have found some problem. Please try to check the build at the following link:
https://www.dropbox.com/s/ataalebn92u10 ... l.zip?dl=0

Thank you.
thesaurus
Posts: 5
Joined: Wed Nov 02, 2016 4:36 pm

Re: Loading a base64-encoded image (DataColumn, Image)

Post by thesaurus »

Thanks for your reply!

Could you attach the corrected file version? Honestly, I don't see where I should rename the column name.

Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Loading a base64-encoded image (DataColumn, Image)

Post by Alex K. »

Hello,

please check the last build 2016.2.9 from 2016.11.26 from our site.

Thank you.
thesaurus
Posts: 5
Joined: Wed Nov 02, 2016 4:36 pm

Re: Loading a base64-encoded image (DataColumn, Image)

Post by thesaurus »

Thanks for your reply!

For us it works now with the current Stimulsoft.JS version 2016.3.

If anyone is following this post, we had to register a corresponding column within the <Dictionary/> to make it work. Aleksey mentioned this a bit above.

Code: Select all

    <DataSources isList="true" count="1">
      <ServiceDispo Ref="2" type="DataTableSource" isKey="true">
        <Alias>ServiceDispo</Alias>
        <Columns isList="true" count="5">
          <value>servicedispo_servicedispono,System.String</value>
          <value>servicedispo_description,System.String</value>
          <value>employee_name1,System.String</value>
          <value>employee_name2,System.String</value>
          <value>employee_picture,System.String</value>
          <value>image,System.String</value>
          <value>image2,System.String</value>
        </Columns>
        <Dictionary isRef="1" />
        <Name>ServiceDispo</Name>
        <NameInSource>ServiceDispo.ServiceDispo</NameInSource>
      </ServiceDispo>
    </DataSources>
The missing part was:

Code: Select all

          <value>image,System.String</value>
          <value>image2,System.String</value>
Please find a working example attached.

Thank you again.
Attachments
try-stimu.zip
Working version
(3.47 MiB) Downloaded 607 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Loading a base64-encoded image (DataColumn, Image)

Post by HighAley »

Hello.

Thank you for posting your solution.
Post Reply