How to prevent download of exported CSV file before it's ready?

Hi,

So I am generating reports which I then present the user a button to export the report.

When they click on the export button I run Export CSV File in server action.

Once I get a success on the server action I start the download of the file.

My problem is depending on the size of the report, the excel file is sometimes still being written to, and therefore I get one of two issues.

The first one I get some of the times.
"Message": "The process cannot access the file 'C:\\wwwMe2You\\reports\\3_21-Apr-2020-1509_Report.csv' because it is being used by another process.",

Or the second is the download will start and somehow pull down the file missing a lot of data because the file had not finished being written to.

As the server action sends back a success even though the files are still been written too there is no way to prevent the download from starting.

How can I overcome this issue?

Thanks,
Ray

I’m sure its well too late, but you could put the steps into a workflow and add a ‘wait’ step before commencing the download.