Vertx Web API 使用 OpenAPI3RouterFactory 和 EventBus 上传服务文件

Vertx Web API Service File uploading using OpenAPI3RouterFactory and EventBus

我正在尝试使用 Vert.x Web API 合同定义服务接口与 OpenAPI 操作定义,在 Rest API 中上传文件和其他相关数据,如下所示: -

/api/pets/{petId}/uploadImage:
post:
  summary: upload file for pet
  operationId: savePetPicture
  x-vertx-event-bus: "petstore_manager.myapp"
  parameters:
    - name: petId
      in: path
      required: true
      description: The id of the pet
      schema:
        type: string
  requestBody:
    description: image to be used as pet picture
    content:
      multipart/form-data:
        schema:
          type: object
          properties:
            profileImage:
              type: string
              format: binary
            name:
              type: string

我有一个服务接口 PetStoreManagerService,我在其中定义了处理此资源操作的方法。

@WebApiServiceGen
public interface PetStoreManagerService {
    void savePetPicture(PetImage body, String petId, OperationRequest operationRequest,
                      Handler<AsyncResult<OperationResponse>> handler);
}

和模型class定义如下

@DataObject(generateConverter = true, publicConverter = false)
public class PetImage {
  String name;
  Buffer profileImage;
}

我在我的项目中遵循了这个教程。 vertx-web-api-service tutorial 我的问题是这个 PetImage class 中的 profileImage 的类型应该是什么?我在我的服务实现 class.

中得到的 requestBody 为空

我发现一些 post 操作在 MainVerticle class 中处理,如

routerFactory.addHandlerByOperationId("savePetPicture",  routingContext -> {
Set<FileUpload> fileUploadSet = routingContext.fileUploads();
Iterator<FileUpload> fileUploadIterator = fileUploadSet.iterator();
// ...

我想知道这是否可以在服务 class 中处理,将请求路由到 PetStoreManagerService 实现 class,如教程中所示。

事件总线不是为处理大负载而设计的(主要是因为它缺少字节流),因此您不应尝试通过它执行文件上传。

vert.x 邮件列表上有一堆帖子,我鼓励您阅读解释问题的帖子:

如果您需要实现处理文件上传的 OpenAPI 操作,您应该使用通常的 Vert.x Web 处理程序来实现它,如解释的那样 here and retrieve the file uploads as explained here