Reputation: 1029
For a legacy project I need to work with react-js and especially with the outdated reactFileDownload module.
Therefore, I am facing the problem of doing an API call to a server AFTER the user has downloaded a single file. For waiting on download I have seen
How do i wait until a file is done downloading (ObjectiveC) and
WebClient - wait until file has downloaded C#
Since the documentation on npm about reactFileDownload is - well - a 2 liner, maybe someone can give me a hint, how to do a
await <reactFileDownload()>
.then(() => {proceed()})
in node.js.
Thanks,
Upvotes: 0
Views: 2460
Reputation: 1245
Try this -
var fileDownload = require('react-file-download');
var promise = new Promise((resolve, reject) => {
fileDownload(data, 'filename.csv');
// wait 2 sec then resolve
setTimeout(() => { resolve(true) }, 2000);
});
Then you can do -
await promise().then(result => console.log(result)).catch(err => console.log(err.message));
Upvotes: 1