我想用Vertx上傳文件,請求是包含PDF的POST請求,我的處理程序看起來像這樣(我從github中的示例代碼):發送文件到vertx事件總線
...
Set<FileUpload> fileUploadSet = routingContext.fileUploads();
Iterator<FileUpload> fileUploadIterator = fileUploadSet.iterator();
while (fileUploadIterator.hasNext()) {
FileUpload fileUpload = fileUploadIterator.next();
// Use the Event Bus to dispatch the file now
// Since Event Bus does not support POJOs by default so we need to create a MessageCodec implementation
// and provide methods for encode and decode the bytes
...
vertx.eventBus().<"what to use here?">send(Address.UPLOAD_FILE, "", result -> {
if (result.succeeded()) {
req.response()
.setStatusCode(200)
.write(result.result().body())
.end();
} else {
logger.info(result.cause().toString());
req.response()
.setStatusCode(500)
.write(result.cause().toString())
.end();
}
});
根據上述評論,我不能只是嘗試這樣的事情(它實際上顯示錯誤):
vertx.eventBus().<FileUpload>send(Address.UPLOAD_FILE, "", result -> {
我一直在檢查MessageCodec但它不是我清楚如何應用它對於這種情況。
注:事件總線的使用是這個情景的必要條件。