NetTalk Central

Author Topic: base64 encoded string won't save to file after str.base64Decode()  (Read 5305 times)

joep

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Email
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
 

joep

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Email
Re: base64 encoded string won't save to file after str.base64Decode()
« Reply #1 on: August 03, 2018, 06:05:11 AM »
The save is working know, but the word file seems to be corrupted.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: base64 encoded string won't save to file after str.base64Decode()
« Reply #2 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


joep

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Email
Re: base64 encoded string won't save to file after str.base64Decode()
« Reply #3 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