0

I have a front end that lists documents, when a user clicks to download it will call the API and request a URL with a Amazon Storage SAS token. This happens async, so may take a short moment. Once the URL is returned how can I then trigger the download?

I cant pre fetch the URL as it has a SAS token that expires after a period of time, the user may easily wait past that period of time before fetching the document and would get a access denied error.

I cant use a anchor tag as the URL is not known at the time of click. I could create a new button that says download, but now the user presses download twice, for one file. Is there a way to trigger a download? Perhaps in useEffect ?

1 Answer 1

1
 async donwloadWookLog(id) { const blob = await this.workLogService.getWorklog(id) .catch(error => { this.notify.showMessage('Unable to download work log.', 2000); }); const url = window.URL.createObjectURL(blob); const link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = 'work_log_' + id+' .xlsx'; link.click(); window.URL.revokeObjectURL(url); } 

TS code sample

Sign up to request clarification or add additional context in comments.

Comments