I have a situation where users are storing pdfs in a SQL table. I have a SQL query that is taking in the file name and bytes, converting the bytes to Varbinary(MAX).
Scripting on FileUpload action:
Name = event.file.name
data = event.file.getBytes()
system.db.runNamedQuery('FileUploadTest', {"FileData":data, 'FileName':Name})
If you notice on the button scripting, I have been attempting two methods. The first pulls the data via the correlated query. This pulls up the file explorer and allows name input, but it does not save a file when save is pressed. The second is FromTable, in which the data is passed from the selected row on the table component. This pulls up the file explorer and downloads the file in the correct format. However, it is corrupted and does not show as intended. Example photo:
I have seen extensive documentation on the forum, with many turning towards third-party modules or retrieving files from the gateway. Permissions and securities at my current place of employment prevent me from using either.
Is there some function or datatype that I can pull within the scripting that will pass this varbinary(max) back as the original bytearray? Or some other solution? My best guess is that it's not passing as the correct datatype. Please let me know if this is possible.
Microsoft SQL Server Management Studio 17. I wonder, did you run yours as a named query or passed it within the script? That might be a difference maker.
I can play around with the base64 import, but I might run out of my hours today before I get to it, so I might have to update progress tomorrow. Thank you for the help!
I couldn't find a simple way to do it in the scripting. While it is easy to convert within the query towards the DB, I could not find a way to convert it back to bytearray from the DB towards the script. byte(), bytearray(), bytes(), byte, array(), to no luck. There might be a standard way to do this that I just haven't found yet.
Might be interesting to push a test pdf (with no sensitive data like payrolls xP)
And give the resulting output as you saw in the table, the bytes. Then we could check if its a conversion/encoding error
For me, I was having the same issue with retrieving the image as a BLOB or varbinary from MSSQL so I ended up using the above to convert my array to a python byte array, and then I have been storing the data as a Base64 string in the database.
I do not suggest using base64 for your use, but the conversion may work for you coming out of the database query into the pdf download function.