Created
April 21, 2016 21:50
-
-
Save antishok/9a85e5e216bb099228b16ff69f0e0221 to your computer and use it in GitHub Desktop.
bhttp + multer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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