assertEquals(req.path(), "/form"); req.setExpectMultipart(true); req.uploadHandler(event -> event.handler(buffer -> { fail("Should not get here"); }));
req.response().setChunked(true); req.setExpectMultipart(true); req.uploadHandler(upload -> upload.handler(buffer -> { fail("Should get here"); }));
String uploadedFileName; if (!streamToDisk) { upload.handler(tot::appendBuffer); uploadedFileName = null; } else {
public io.vertx.rxjava.core.http.HttpServerFileUpload handler(Handler<io.vertx.rxjava.core.buffer.Buffer> handler) { delegate.handler(new Handler<io.vertx.core.buffer.Buffer>() { public void handle(io.vertx.core.buffer.Buffer event) { handler.handle(io.vertx.rxjava.core.buffer.Buffer.newInstance(event)); } }); return this; }
public io.vertx.rxjava.core.http.HttpServerFileUpload handler(Handler<io.vertx.rxjava.core.buffer.Buffer> handler) { delegate.handler(new Handler<io.vertx.core.buffer.Buffer>() { public void handle(io.vertx.core.buffer.Buffer event) { handler.handle(io.vertx.rxjava.core.buffer.Buffer.newInstance(event)); } }); return this; }
/** * Checks whether we exceed the max allowed file size. * * @param newSize the expected size once the current chunk is consumed * @param maxSize the max allowed size. * @param upload the upload */ private void checkSize(long newSize, long maxSize, HttpServerFileUpload upload) { if (maxSize >= 0 && newSize > maxSize) { upload.handler(null); report(new IllegalStateException("Size exceed allowed maximum capacity")); } }
req.response().setChunked(true); req.setExpectMultipart(true); req.uploadHandler(upload -> upload.handler(buffer -> { fail("Should get here"); }));
assertEquals(req.path(), "/form"); req.setExpectMultipart(true); req.uploadHandler(event -> event.handler(buffer -> { fail("Should not get here"); }));
String uploadedFileName; if (!streamToDisk) { upload.handler(tot::appendBuffer); uploadedFileName = null; } else {
.error("Cannot read the uploaded item {} ({})", upload.name(), upload.filename(), event)) .endHandler(event -> delegate.close()) .handler( event -> { if (event != null) {
private void testFileUploadFormMultipart(int size) throws Exception { Buffer content = Buffer.buffer(TestUtils.randomAlphaString(size)); vertx.fileSystem().writeFileBlocking(testFile.getPath(), content); server.requestHandler(req -> { req.setExpectMultipart(true); req.uploadHandler(upload -> { Buffer fileBuffer = Buffer.buffer(); assertEquals("file", upload.name()); assertEquals("test.txt", upload.filename()); assertEquals("text/plain", upload.contentType()); upload.handler(fileBuffer::appendBuffer); upload.endHandler(v -> assertEquals(content, fileBuffer)); }); req.endHandler(v -> { assertEquals("vert.x", req.getFormAttribute("toolkit")); assertEquals("jvm", req.getFormAttribute("runtime")); req.response().end(); }); }); startServer(); MultipartForm form = MultipartForm.create() .attribute("toolkit", "vert.x") .attribute("runtime", "jvm") .textFileUpload("file", testFile.getName(), testFile.getPath(), "text/plain"); HttpRequest<Buffer> builder = client.post("somepath"); builder.sendMultipartForm(form, onSuccess(resp -> complete())); await(); }