-
-
Save lirongfei123/d13c81a57ee2c61a3f7f1d0f81f4e593 to your computer and use it in GitHub Desktop.
express #express
This file contains hidden or 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 Busboy = require('busboy'); | |
| var busboy = new Busboy({ headers: req.headers }); | |
| return new Promise((resolve) => { | |
| busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { | |
| const buffers = []; | |
| file.on('data', function(data) { | |
| buffers.push(data); | |
| }); | |
| file.on('end', () => { | |
| co(function* () { | |
| const result = yield client.put(`${userid}/${uuidv3(filename, uuidv3.DNS)}-${filename}`, Buffer.concat(buffers)); | |
| resolve({ | |
| url: result.url, | |
| name: result.name | |
| }); | |
| }); | |
| }); | |
| }); | |
| busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) { | |
| console.log('Field [' + fieldname + ']: value: '); | |
| }); | |
| req.pipe(busboy); | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment