node.js - Sending a buffer to the client to download -
i have buffer download on node.js server dropbox. i'd send buffer (or convert file , send it) client, , have begin downloading on client side. missing here?
var client = dboxapp.client(req.session.dbox_access_token); client.get(req.body.id, function(status, data, metadata) { // do here? })
here's angular (uses promise). when console.log(response object includes buffer).
function(id, cloud){ return $http.post('/download/'+cloud, {id: id}).then(function(response){ console.log(response) }, function(response) { return $q.reject(response.data); }) }
it looks dbox
module you're using has stream()
option better suited file downloads. should make call metadata
file's mime type. example:
var middleware = function(req, res, next) { var client = dboxapp.client(req.session.dbox_access_token); var file = req.body.id; client.metadata(file, function(status, reply) { res.setheader('content-disposition', 'attachment; filename=' + file); res.setheader('content-type', reply.mime_type); client .stream(file) .pipe(res) .on('error', next); }); };
Comments
Post a Comment