简体   繁体   中英

Multiple file append in response object in node js

gfs.files.find({}).toArray(function(err, file) {
    if (!err) {
        console.log('file length ', file.length);
        if (file.length > 0) {
            file.forEach(function(each) {
                process.setMaxListeners(0);
                var mime = 'image/jpeg';
                res.set('Content-Type', mime);
                read_stream = gfs.createReadStream({ "filename": each.filename });
                read_stream.pipe(res, { end: false });
                done++;
            });
            read_stream.on('end', function() {
                process.setMaxListeners(0);
                if (done === file.length) {
                    res.send();
                }

            });

        } else {
            res.json('File Not Found');
        }
    }
});

It is not work properly.Only one file is shown in browser.what i do now?It will be without any zip file.

If your target clients are web browsers, then you can't, as the http protocol does not allow for multiple downloads for a single request.

May be you can think of creating an archive(zip) with requested files and send it.

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