【问题标题】:Vertx Web API Service File uploading using OpenAPI3RouterFactory and EventBus使用 OpenAPI3RouterFactory 和 EventBus 上传 Vertx Web API 服务文件
【发布时间】:2020-09-02 13:33:18
【问题描述】:

我正在尝试使用 Vert.x Web API Contract 使用 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);
}

Model类定义如下

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

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

我发现一些帖子在 MainVerticle 类中处理操作

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

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

【问题讨论】:

    标签: java vert.x


    【解决方案1】:

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

    在 vert.x 邮件列表上有一堆帖子我鼓励你阅读这些帖子来解释这个问题:

    如果您需要实现处理文件上传的 OpenAPI 操作,您应该使用通常安装的 Vert.x Web 处理程序来实现它,如here 所述,并如here 所述检索文件上传

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-02
      • 2017-11-01
      相关资源
      最近更新 更多