Skip to content

Instantly share code, notes, and snippets.

@lirongfei123
Created February 11, 2019 03:28
Show Gist options
  • Select an option

  • Save lirongfei123/d13c81a57ee2c61a3f7f1d0f81f4e593 to your computer and use it in GitHub Desktop.

Select an option

Save lirongfei123/d13c81a57ee2c61a3f7f1d0f81f4e593 to your computer and use it in GitHub Desktop.
express #express
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