本文整理了Java中io.vertx.ext.web.client.HttpRequest.sendMultipartForm()
方法的一些代码示例,展示了HttpRequest.sendMultipartForm()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.sendMultipartForm()
方法的具体详情如下:
包路径:io.vertx.ext.web.client.HttpRequest
类名称:HttpRequest
方法名:sendMultipartForm
暂无
代码示例来源:origin: vert-x3/vertx-rx
/**
* Like {@link io.vertx.rxjava.ext.web.client.HttpRequest#send} but with an HTTP request <code>body</code> multimap encoded as form and the content type
* set to <code>multipart/form-data</code>. You may use this method to send attributes and upload files.
* @param body the body
* @param handler
*/
public void sendMultipartForm(io.vertx.rxjava.ext.web.multipart.MultipartForm body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) {
delegate.sendMultipartForm(body.getDelegate(), new Handler<AsyncResult<io.vertx.ext.web.client.HttpResponse<T>>>() {
public void handle(AsyncResult<io.vertx.ext.web.client.HttpResponse<T>> ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(ar.result(), __typeArg_0)));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* Like {@link io.vertx.rxjava.ext.web.client.HttpRequest#send} but with an HTTP request <code>body</code> multimap encoded as form and the content type
* set to <code>multipart/form-data</code>. You may use this method to send attributes and upload files.
* @param body the body
* @param handler
*/
public void sendMultipartForm(io.vertx.rxjava.ext.web.multipart.MultipartForm body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) {
delegate.sendMultipartForm(body.getDelegate(), new Handler<AsyncResult<io.vertx.ext.web.client.HttpResponse<T>>>() {
public void handle(AsyncResult<io.vertx.ext.web.client.HttpResponse<T>> ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(ar.result(), __typeArg_0)));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testFileUploadWhenFileDoesNotExist() {
HttpRequest<Buffer> builder = client.post("somepath");
MultipartForm form = MultipartForm.create()
.textFileUpload("file", "nonexistentFilename", "nonexistentPathname", "text/plain");
builder.sendMultipartForm(form, onFailure(err -> {
assertEquals(err.getClass(), HttpPostRequestEncoder.ErrorDataEncoderException.class);
complete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
req.sendJson("", handler);
req.sendJsonObject(new JsonObject(), handler);
req.sendMultipartForm(MultipartForm.create().attribute("a", "b"), handler);
代码示例来源:origin: io.vertx/vertx-web-client
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();
}
内容来源于网络,如有侵权,请联系作者删除!