Skip to content

Instantly share code, notes, and snippets.

@antishok
Created April 21, 2016 21:50
Show Gist options
  • Save antishok/9a85e5e216bb099228b16ff69f0e0221 to your computer and use it in GitHub Desktop.
Save antishok/9a85e5e216bb099228b16ff69f0e0221 to your computer and use it in GitHub Desktop.
bhttp + multer
var stream = require('stream');
var bhttp = require('bhttp');
var Promise = require('bluebird');
Promise.try(function() {
return bhttp.get('http://www.pdf995.com/samples/pdf.pdf');
}).then(function(response) {
var bufferStream = new stream.PassThrough();
bufferStream.end(response.body);
var data = {
from: 'whatever',
to: 'whatever',
files: bhttp.wrapStream(bufferStream, {filename: 'bla.pdf'})
};
return bhttp.post('http://localhost:3000', data);
});
var express = require('express');
var multer = require('multer');
var app = express();
var storage = multer.memoryStorage();
var upload = multer({ storage: storage });
app.post('/', upload.any(), function(req, res, next) {
console.log('got pdf', req.files);
res.end('bye');
});
app.listen(3000)
console.log('listening');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment