remove old upload example
This commit is contained in:
parent
33846d1b95
commit
f28dee3423
3 changed files with 0 additions and 86 deletions
|
@ -1,51 +0,0 @@
|
|||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var logger = require('koa-logger');
|
||||
var serve = require('koa-static');
|
||||
var parse = require('co-busboy');
|
||||
var koa = require('../..');
|
||||
var fs = require('fs');
|
||||
var app = koa();
|
||||
|
||||
// log requests
|
||||
|
||||
app.use(logger());
|
||||
|
||||
// custom 404
|
||||
|
||||
app.use(function *(next){
|
||||
yield next;
|
||||
if (this.body || !this.idempotent) return;
|
||||
this.redirect('/404.html');
|
||||
});
|
||||
|
||||
// serve files from ./public
|
||||
|
||||
app.use(serve(__dirname + '/public'));
|
||||
|
||||
// handle uploads
|
||||
|
||||
app.use(function *(next){
|
||||
// ignore non-POSTs
|
||||
if ('POST' != this.method) return yield next;
|
||||
|
||||
// multipart upload
|
||||
var parser = parse(this);
|
||||
var part;
|
||||
|
||||
while (part = yield parser.part()) {
|
||||
var stream = fs.createWriteStream('/tmp/' + Math.random());
|
||||
part.pipe(stream);
|
||||
console.log('uploading %s -> %s', part.filename, stream.path);
|
||||
}
|
||||
|
||||
this.redirect('/');
|
||||
});
|
||||
|
||||
// listen
|
||||
|
||||
app.listen(3000);
|
||||
console.log('listening on port 3000');
|
|
@ -1,15 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Not Found</title>
|
||||
<style>
|
||||
body {
|
||||
padding: 50px;
|
||||
font: 14px Helvetica, Arial;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Sorry! Can't find that.</h1>
|
||||
<p>The page you requested cannot be found.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,20 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Upload</title>
|
||||
<style>
|
||||
body {
|
||||
padding: 50px;
|
||||
font: 14px Helvetica, Arial;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>File Upload</h1>
|
||||
<p>Try uploading multiple files at a time.</p>
|
||||
<form action="/" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="file" multiple>
|
||||
<input type="submit" value="Upload">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue