@Override public void start() throws Exception { vertx.createHttpServer().requestHandler(req -> { if (req.uri().equals("/")) { // Serve the index page req.response().sendFile("index.html"); } else if (req.uri().startsWith("/form")) { req.setExpectMultipart(true); req.uploadHandler(upload -> { upload.exceptionHandler(cause -> { req.response().setChunked(true).end("Upload failed"); }); upload.endHandler(v -> { req.response().setChunked(true).end("Successfully uploaded to " + upload.filename()); }); // FIXME - Potential security exploit! In a real system you must check this filename // to make sure you're not saving to a place where you don't want! // Or better still, just use Vert.x-Web which controls the upload area. upload.streamToFileSystem(upload.filename()); }); } else { req.response().setStatusCode(404); req.response().end(); } }).listen(8080); } }
public io.vertx.rxjava.core.http.HttpServerFileUpload exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return this; }
FileUploadImpl fileUpload = new FileUploadImpl(uploadedFileName, upload); fileUploads.add(fileUpload); upload.exceptionHandler(t -> { deleteFileUploads(); context.fail(t);
public io.vertx.rxjava.core.http.HttpServerFileUpload exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return this; }
FileUploadImpl fileUpload = new FileUploadImpl(uploadedFileName, upload); fileUploads.add(fileUpload); upload.exceptionHandler(t -> { deleteFileUploads(); context.fail(t);
BHandler(RoutingContext context) { this.context = context; Set<FileUpload> fileUploads = context.fileUploads(); final String contentType = context.request().getHeader(HttpHeaders.CONTENT_TYPE); isMultipart = contentType != null && contentType.contains("multipart/form-data"); isUrlEncoded = contentType != null && contentType.contains("application/x-www-form-urlencoded"); if (isMultipart || isUrlEncoded) { makeUploadDir(context.vertx().fileSystem()); context.request().setExpectMultipart(true); context.request().uploadHandler(upload -> { // *** cse begin *** if (uploadsDir == null) { failed = true; CommonExceptionData data = new CommonExceptionData("not support file upload."); throw new ErrorDataDecoderException(ExceptionFactory.createConsumerException(data)); } // *** cse end *** // we actually upload to a file with a generated filename uploadCount.incrementAndGet(); String uploadedFileName = new File(uploadsDir, UUID.randomUUID().toString()).getPath(); upload.streamToFileSystem(uploadedFileName); FileUploadImpl fileUpload = new FileUploadImpl(uploadedFileName, upload); fileUploads.add(fileUpload); upload.exceptionHandler(context::fail); upload.endHandler(v -> uploadEnded()); }); } context.request().exceptionHandler(context::fail); }
@Override public void handle(final HttpServerFileUpload fileUpload) { if (request.files() == null) { request.setFiles(new HashMap<String, YokeFileUpload>()); } final YokeFileUpload upload = new YokeFileUpload(vertx(), fileUpload, uploadDir); // setup callbacks fileUpload.exceptionHandler(new Handler<Throwable>() { @Override public void handle(Throwable throwable) { next.handle(throwable); } }); // stream to the generated path fileUpload.streamToFileSystem(upload.path()); // store a reference in the request request.files().put(fileUpload.name(), upload); // set up a callback to remove the file from the file system when the request completes request.response().endHandler(new Handler<Void>() { @Override public void handle(Void event) { if (upload.isTransient()) { upload.delete(); } } }); } });
FileUploadImpl fileUpload = new FileUploadImpl(uploadedFileName, upload); fileUploads.add(fileUpload); upload.exceptionHandler(t -> { deleteFileUploads(); context.fail(t);
FileUploadImpl fileUpload = new FileUploadImpl(uploadedFileName, upload); fileUploads.add(fileUpload); upload.exceptionHandler(t -> { deleteFileUploads(); context.fail(t);
delegate = new MemoryFileUpload(upload, errorHandler); upload.exceptionHandler(event -> LoggerFactory.getLogger(MixedFileUpload.class) .error("Cannot read the uploaded item {} ({})", upload.name(), upload.filename(), event)) .endHandler(event -> delegate.close())