Export Data - Choose or create export file

results = system.db.runNamedQuery("Fetch Records",{})
spreadsheet = system.dataset.toExcel(True, [results])
filePath = "C:\\output\\results.xlsx"
system.file.writeFile(filePath, spreadsheet)

Instead of hard coding the filepath - can the client choose a file location or create a new one if they wish ???

Which UI?

If Vision, there are utilities to pop up a file/folder selection.

If Perspective, you must use system.perspective.download(), and cannot dictate where the file ends up, and can only suggest a file name.

If this will run in the gateway to save into the gateway filesystem, you will need to provide a file path through some indirect means.

Thanks could you elaborate on how something could run in the gateway and not perspective ?

I would expect the user of a Perspective UI to want a file to be placed in the machine on which the client browser is running. You cannot write from a script to a client browser's local filesystem. (Nor read anything, either.) Browsers don't allow that malware-ish behavior.

There are many reasons a script running in a gateway might want to write into a file in the gateway, but it wouldn't be expected to be accessible to any client.

What about a file upload component - if the script is running in perspective and the client uses that component with that script.

Sure, if you are uploading, you might expect to save in the gateway. If you want client control over the file name (potentially dangerous!), give them a text field for that. Giving them any option to pick an arbitrary destination folder in the gateway is crazy.

1 Like

So are you saying I create and store files in the gateway?

It's up to you.

What are you actually trying to do?
The File Upload component creates temporarily files on the gateway when files are uploaded. Their location is deliberately obscured from you - they should be treated as ephemeral unless explicitly saved somewhere by you. That can be a database table with a BLOB column, a specific directory on the filesystem, into an S3 bucket via system.net.httpClient, whatever - it's up to you.

I want to export data from a chart to a workbook.

If you ultimately want that export to end up on whatever user agent is actually viewing your Perspective project (web browser, mobile device, workstation session) your only option is system.perspective.download, subject to the restrictions Phil mentioned above. This isn't something we (IA) can work around - it's a fundamental behavior of web browsers that they don't allow you to look at the local filesystem, so all you can do is give the user agent a download link and hope that it will accept downloading your file with the filename you suggested.

3 Likes