Downloading documents generated by Python

HI all,

I’m on NG-client 2023.03.x.

I have a Python script that generates Word documents. I would like my users to click a button and get the Word document as a download.
It does not seem to be possible to pass the binary data the script generates using application.executeProgram as this returns Strings.

Have anyone done integrations like this? Where do I get Python to save files so they can be read by the Servoy server?

Thanks,

Hi Christian,

As executeProgram returns a string, would it be possible to let Python return the doc as base64?

Then it would be pretty easy:

var _aBytes = utils.base64ToBytes(_sPythonB64)
			plugins.file.writeFile('myWordDocument.docx', _aBytes)

Otherwise, you should let Python write the file to a location which can be accessed by the application_server.
Then you can just read the bytes from that file and use the same writeFile command as above.

Hi Mark,

Thank you for confirming the approach, I seem to have a problem on the Python side, my data does not look Base64 encoded.

....GOk\xc6\x05\\\x10U\x91R\xbc\xa7\x9fH\xeb^\xb5\'\xb8H\xa5\x8....

Got it working now. It turns out the binary data is padded when it is output from Python. There was a b' at the front and a ```

This caused the base64 conversion on the Servoy side to fail.

Thanks for your help, Marc.