diff --git a/upload/app.js b/upload/app.js index 1a01aec..0b067c3 100644 --- a/upload/app.js +++ b/upload/app.js @@ -36,11 +36,16 @@ app.use(async function(ctx, next) { // ignore non-POSTs if ('POST' != ctx.method) return await next(); - const file = ctx.request.body.files.file; - const reader = fs.createReadStream(file.path); - const stream = fs.createWriteStream(path.join(os.tmpdir(), Math.random().toString())); - reader.pipe(stream); - console.log('uploading %s -> %s', file.name, stream.path); + var files = ctx.request.body.files.file; + if (!Array.isArray(files)) { + files = new Array(files); + } + files.forEach(function(file, index) { + const reader = fs.createReadStream(file.path); + const stream = fs.createWriteStream(path.join(os.tmpdir(), Math.random().toString())); + reader.pipe(stream); + console.log('uploading %s -> %s', file.name, stream.path); + }); ctx.redirect('/'); });