简体   繁体   中英

How to save buffer data into a file using browser javascript?

I have a pdf buffer data coming from my nodeJS backend, something like..

"%PDF-1.5 % ..."

How can I save this into a file using browser's javascript ?

You can save it as a file on the NodeJS end, and then download the file using javascript. That is probably the best way, as javascript does not have access to writing to the file system.

Sorry for late reply,You can do piping like this:

    filepath = 'test.pdf';

    var dest = fs.createWriteStream(filepath);
        request(options, function (error, response, body) {
            if (error)
                throw new Error(error);

        }).on('end', function () {
            return callback(filepath);
        }).on('error', function (err) {
            return callback(err);
        }).pipe(dest);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM