Vertxアップロード公式サイトDemo JavaScript版


var Router = require("vertx-web-js/router");
var BodyHandler = require("vertx-web-js/body_handler");

var router = Router.router(vertx);

// Enable multipart form data parsing
router.route().handler(BodyHandler.create().handle);

router.route("/").handler(function (routingContext) {
  routingContext.response().putHeader("content-type", "text/html").end("<form action=\"/form\" method=\"post\" enctype=\"multipart/form-data\">
<div>
<label for=\"name\">Select a file:</label>
<input type=\"file\" name=\"file\" />
</div>
<div class=\"button\">
<button type=\"submit\">Send</button>
</div></form>"); }); // handle the form router.post("/form").handler(function (ctx) { ctx.response().putHeader("Content-Type", "text/plain"); ctx.response().setChunked(true); Array.prototype.forEach.call(ctx.fileUploads(), function(f) { console.log("f"); ctx.response().write("Filename: " + f.fileName()); ctx.response().write("
"); ctx.response().write("Size: " + f.size()); }); ctx.response().end(); }); vertx.createHttpServer().requestHandler(router.accept).listen(8080);