Extract Image vom XML file (with embedded Image)

Discussion forum about all things Team Developer 5.x and 6.x
klaushaidinger
Austria
Posts: 108
Joined: 13 Dec 2017, 06:08
Location: Austria

Extract Image vom XML file (with embedded Image)

Post by klaushaidinger » 02 Mar 2020, 13:25

Dear Community!
Has anyone ever extracted an image from an XML file - embedded as a BASE64 string and saved it as e.g. jpg?
I have already tried with the following code:

Call SalStrSetBufferLength( spSrc, npSrcLen*2 )
Set nlRetVal = CryptStringToBinaryW( spSrc, npSrcLen, CRYPT_STRING_BASE64, spBLOB, spBLOBLen, nlSkip, nlFlags )

But it does not seem to work.
Thanks for your help!

a_sivababu
India
Posts: 524
Joined: 10 Mar 2017, 08:46
Location: Chennai,India

Re: Extract Image vom XML file (with embedded Image)

Post by a_sivababu » 02 Mar 2020, 15:01


klaushaidinger
Austria
Posts: 108
Joined: 13 Dec 2017, 06:08
Location: Austria

Re: Extract Image vom XML file (with embedded Image)

Post by klaushaidinger » 02 Mar 2020, 17:13

Yes, i did. My test was based on this example and the following hints.
But it still doesn´t work ..:-/

a_sivababu
India
Posts: 524
Joined: 10 Mar 2017, 08:46
Location: Chennai,India

Re: Extract Image vom XML file (with embedded Image)

Post by a_sivababu » 03 Mar 2020, 03:24

OkK. Can you please post sample app here and also let us know what TD Version you are currently using.

Riuks
Estonia
Posts: 16
Joined: 10 Mar 2017, 07:41
Location: Tallinn, Estonia

Re: Extract Image vom XML file (with embedded Image)

Post by Riuks » 03 Mar 2020, 12:09

I have SOAP solution where xml contains pdf file.
I think thats not difference what are inside BASE64...

##################################################################################################################

Sending into SOAP:
1) Set sPdfBase64 = SalBinaryToString( binPdf, ENC_BASE64)
2) Set sXMLBase64 = SalBinaryToString( SalStringToBinary(sXML, ENC_UTF8) , ENC_BASE64)
* sXML is just a simple string which is randomly in xml format

3) Set gString='<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<FWDINVOICE xmlns="TresoorInvoice">
<data>
<INVOICE_PDF_FILE>'||sPdfBase64||'</INVOICE_PDF_FILE>
<INVOICE_XML_FILE>'||sXMLBase64||'</INVOICE_XML_FILE>
</data>
</FWDINVOICE>
</soap:Body>
</soap:Envelope>
'
And this goes into SOAP-service reguest as string parameter :
4) oTresoorEInvoice.TTfSendFwdInvoice( gString, gLString )
NB! Here big thanks to Dave Rabelink for sample https://wiki.tdcommunity.net/index.php/ ... t_XMLHTTP
to consume normally (low code) SOAP:

..uMSXMLDocSoapRequest.loadXML( psRequest, bLoaded ) AND bLoaded
...uHTTP.send( uVariantBody )
....

##################################################################################################################

SOAP Service
5) My SOAP service which saves all into DB is created with TDM: Data Operation: FWDINVOICE (add) saves into Gupta DB.
Data Class INVOICE
String: INVOICE_PDF_FILE
String: INVOICE_XML_FILE

Gupta TB table:
NAME COLTYPE LENGTH NULLS
==================================== ======== =========== =====
INVOICE_XML_FILE LONGNCHR 0 Y
INVOICE_PDF_FILE LONGVAR 0 Y

##################################################################################################################


Read INVOICE_PDF_FILE which is inside SQLBase table into string variable oString.
At this point we had to create external dll to get things working and called that dll inside TDM or TD like this:
Call oTresoor.CLTresoor()
Set binBin= oTresoor.GetByteArrayFromBase64(oString)
Save file:
If SalFileOpen(hFile, sName||'.pdf' , OF_Create| OF_Write)
If SalFileWrite(hFile, binBin, 3000000)
Call SalFileClose(hFile)


##################################################################################################################


DLL:
Visual Studio:

namespace CLTresoorsignNet
{
public class CLTresoor
{

public byte[] GetByteArrayFromBase64(string base64)
{
return Convert.FromBase64String(base64);
}

public string GetBase64StringFromByteArray(byte[] barr)
{
return Convert.ToBase64String(barr);
}
public string GetBase64StringFromUTF8String(string str)
{
return GetBase64StringFromByteArray(System.Text.UTF8Encoding.UTF8.GetBytes(str));
}


}
}

###############################################################
But in short way in 7.2 i created sample:
!!CB!! 129
If SalFileOpen ( hFile, dfstrPath , OF_Read | OF_Write )
Set nFailiPikkus = SalFileRead ( hFile, bin, 100000000 )
If NOT SalFileClose ( hFile )
! Error
Return FALSE
Set n=VisStrScanReverse ( dfstrPath, -1, '\\')
If n>-1
Set dfstrFile=SalStrMidX ( dfstrPath, n+1, SalStrLength (dfstrPath) -n-1)
Else
Set dfstrFile=dfstrPath
Set dfstrFile=SalStrLeftX( dfstrFile,100)
If dfstrFile!=''
If nLength>0
Set sEncodedText = SalBinaryToString( bin, ENC_BASE64)
Else
! Error


;###and return from base64string to binary ####
Set binFail = SalStringToBinary( sEncodedText, ENC_BASE64 )
If SalFileOpen( hFile, '_' || dfFile, OF_Create|OF_Write )
If SalFileWrite( hFile, binFail, nLength)
Call SalFileClose( hFile )

Sample.apt attached
Sample.zip
You do not have the required permissions to view the files attached to this post.
Last edited by Riuks on 04 Mar 2020, 22:52, edited 1 time in total.

klaushaidinger
Austria
Posts: 108
Joined: 13 Dec 2017, 06:08
Location: Austria

Re: Extract Image vom XML file (with embedded Image)

Post by klaushaidinger » 03 Mar 2020, 15:46

Please find attached an Example + Textfile with Base64-Encoded Picture as Text.
I´m using TD63
You do not have the required permissions to view the files attached to this post.

klaushaidinger
Austria
Posts: 108
Joined: 13 Dec 2017, 06:08
Location: Austria

Re: Extract Image vom XML file (with embedded Image)

Post by klaushaidinger » 06 Mar 2020, 16:39

Any ideas? Thank you for your help!

a_sivababu
India
Posts: 524
Joined: 10 Mar 2017, 08:46
Location: Chennai,India

Re: Extract Image vom XML file (with embedded Image)

Post by a_sivababu » 07 Mar 2020, 06:29

I do not have TD 6.3 installed. Hope we get response from other developers who is using TD 6.3.

Userj

Re: Extract Image vom XML file (with embedded Image)

Post by Userj » 07 Mar 2020, 16:37

klaushaidinger wrote:
06 Mar 2020, 16:39
Any ideas? Thank you for your help!
Hello Klaus,

I checked your example and fixed some things (see attachment).
- Multiline Field is limited
- the parameters in CryptStringToBinaryW are not correct
- the size for Buffer spBlob must be set before calling CryptStringToBinaryW

klaushaidinger
Austria
Posts: 108
Joined: 13 Dec 2017, 06:08
Location: Austria

Re: Extract Image vom XML file (with embedded Image)

Post by klaushaidinger » 09 Mar 2020, 16:15

Wow - Thank you very, very much!

Return to “General Discussion”

Who is online

Users browsing this forum: [Bing], [Ccbot] and 0 guests