Home download multiple JSON object using URL.revokeObjectURL
Reply: 0

download multiple JSON object using URL.revokeObjectURL

user1045
1#
user1045 Published in April 22, 2018, 10:08 pm

I call the next function two times (I want to download 2 different JSON objects 1 after another):

downloadTestReport(bool, data) {
        let blob = new Blob([JSON.stringify(data)], {
            type: 'application/octet-stream'
        }),
                url = URL.createObjectURL(blob),
                link = document.createElement('a');
        link.setAttribute('href', url);
        let suffix, fileName;
        if (!bool) {
            fileName = 'data',
                    suffix = 'json';
        } else {
            fileName = 'test_report',
                    suffix = 'json';
        }
        link.setAttribute('download', fileName + '.' + suffix);
        console.info("Download file");
        link.click();
        URL.revokeObjectURL(url);
    }

So the issue is that sometime it's download the 1st file only, and sometime it download both the two files.

Any idea why this is happened?

Maby this not good using async function or something?

Thanks,

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30186 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO