NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: joep on August 03, 2018, 05:35:18 AM

Title: base64 encoded string won't save to file after str.base64Decode()
Post by: joep on August 03, 2018, 05:35:18 AM
Hi All,

from a soap request I got a response in xml with several tag's and one tag containing the encoded file.
To save the file to disk I decode it and save it afterwords.
This is the code:

   lExtensie=str.Between('<FileExtension>','</FileExtension>')
   lFile=str.Between('<FileBytes>','</FileBytes>')
   str.SetValue(Clip(lFile))      !***length of the string equals length in xml string (SetValue is correct)
   str.Base64Decode()
   !lFileName='e:\temp\' & Clip(Glo:DmsLastDoc) & Clip(lExtensie)
   lFileName='temp.docx'
   lConnectPos=str.SaveFile(Clip(lFileName))
   message('lFilename=' & Clip(lFilename) &  'Error on Save=' & lConnectPos)          !*** lConnectpos = 0
   If Exists(Clip(lFileName)) Then ShowFoto(Clip(lFileName)).

But str.SaveFile  returns zero.
Any ideas?

Regards,
Joep
 
Title: Re: base64 encoded string won't save to file after str.base64Decode()
Post by: joep on August 03, 2018, 06:05:11 AM
The save is working know, but the word file seems to be corrupted.
Title: Re: base64 encoded string won't save to file after str.base64Decode()
Post by: Bruce on August 03, 2018, 11:28:11 PM
Hi Joep,

not a lot wrong with the code that I can see. Probably I'd optimize it a bit to remove the CLIP;

 lFile=str.Between('<FileBytes>','</FileBytes>')
   str.SetValue(Clip(lFile))     

becomes

   str.SetValue(str.Between('<FileBytes>','</FileBytes>'))     

This removes the need to have an lFile string that's @big enough@ to hold the file. Passing the XML through a STRING, with all the limitations of a string (size / padding) seems prone to failure.

Cheers
Bruce

Title: Re: base64 encoded string won't save to file after str.base64Decode()
Post by: joep on August 05, 2018, 11:44:12 PM
Hi Bruce,

The file appears to be "Pdf" and not Word.
Although the extension tag is <FileExtension>.docx</FileExtension>
Very confusing.
But the code works well.

Thanks,
Joep