0


我想上传头像。我的端点是使用 OpenAPI3RouterFactory(api.yaml 文件)设置的。

api.yaml:

#other endpoints

/api/v1/upload-avatar:
  post:
    summary: Uploading avatars endpoint
    operationId: upload-avatar
    tags:
      - sign up
      - registration

#other ones


HandlerVerticle.kt:

//OpenApi3Router is set
//other endpoints
routerFactory.addHandlerByOperationId("upload-avatar", BodyHandler.create().setDeleteUploadedFilesOnEnd(true).setUploadsDirectory("mp-upload").setMergeFormAttributes(true))
routerFactory.addHandlerByOperationId("upload-avatar", { routingContext -> 
        val fileUploadSet = routingContext.fileUploads()
        val fileUploadIterator = fileUploadSet.iterator()
        while (fileUploadIterator.hasNext()) {
            val fileUpload = fileUploadIterator.next()
            val uploadedFile = vertx.fileSystem().readFileBlocking(fileUpload.uploadedFileName())

            try {
                val fileName = URLDecoder.decode(fileUpload.fileName(), "UTF-8")
                vertx.fileSystem().writeFileBlocking(fileName , uploadedFile)
                routingContext.response().end()
            } catch (e: Exception) {
                e.printStackTrace()
            }


        }
})

//other routes

当我上传图片时,它上传成功,但在服务器端 vertx 创建了错误的上传目录,并且它不会删除临时上传的文件。谁能帮我?

4

1 回答 1

0

不确定这是否应该被认为是一个错误,或者是故意的,但是......

OpenAPI3RouterFactoryImpl.getRouter() 总是覆盖 BodyHandler

不管你之前在那里设置了什么。

我现在开了一个新问题:https ://github.com/vert-x3/vertx-web/issues/860

于 2018-03-13T15:55:28.387 回答