I'm creating a Workflow to create some Word / PDF documents (think Mail Merge) from db query results and I can't see a way to interact with files held in the Retool Storage space directly in JS. Are we limited to the built-in Storage queries or is there a way to interact with files in Storage programatically?
I'm aware that I can get a file from Storage using the mysubdomain.retool.com/api/file/{file id} approach, but what about creating a file?
Based on what I can see, my only option at present is to:
Pull the .docx template in (from RT Storage) via the URL method above
Do the MailMerge, effectively creating a new document (using a JS or Python library)
Output the file stream (base64) to a Retool Storage block in the Workflow to handle the creation / upload to Storage.
I feel as though I'm missing something fundamental here, I'm thinking there must be a way to interact with RT Storage objects in a JS block, if not Python - so any pointers offered are much appreciated.
I think your workflow is setup correctly, but how exactly you are manipulating the files is a bit of an unknown -- you'd likely need a custom docx library but if you have a simple enough template it should be usable within a workflow.
Yes, that's more or less my approach. Unless I'm overlooking something there isn't currently a way to manipulate file objects held in Retool Storage using JS and do the entire operation within a code block - utilising the RT storage blocks, as shown in your example, looks to be the only way.
I'm still experimenting with various Python and JS libraries to find the most suitable, docx-mailmerge looks to be a contender at present (parses mail merge fields and then allows you to populate them before saving the output to a new file), I'll just need to add a base64 converter in there somewhere to enable the return of the base64 string for the following RT Storage stage.
Thank you again, I'm reassured by that and will proceed along these lines.