- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在使用 RestEasy 框架处理 Quarkus 时,我可以使用 MultipartFormDataInput
上传文件。 .此功能按预期工作,但我无法为 swagger UI 提供正确的开放 API 注释。我尝试了多种选择和组合,但都没有结果。请帮我。我在示例代码下方提供。
@Operation(summary = "Upload a single file", description = "Upload a single file")
@APIResponses({
@APIResponse(responseCode = "200", description = "Upload file successfully"),
@APIResponse(name = "500", responseCode = "500", description = "Internal service error") })
@RequestBody(content = @Content(
mediaType = MediaType.MULTIPART_FORM_DATA,
schema = @Schema(type = SchemaType.STRING, format = "binary"),
encoding = @Encoding(name = "attachment", contentType = "application/octet-stream")))
@POST
@Path("/singleFile")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public Response handleFileUpload(@MultipartForm MultipartFormDataInput input) {
String fileName = null;
Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
// Get file data to save
List<InputPart> inputParts = uploadForm.get("attachment");
for (InputPart inputPart : inputParts) {
try {
MultivaluedMap<String, String> header = inputPart.getHeaders();
fileName = getFileName(header);
InputStream inputStream = inputPart.getBody(InputStream.class, null);
byte[] bytes = IOUtils.toByteArray(inputStream);
File customDir = new File(UPLOAD_DIR);
if (!customDir.exists()) {
customDir.mkdir();
}
fileName = customDir.getCanonicalPath() + File.separator + fileName;
Files.write(Paths.get(fileName), bytes, StandardOpenOption.CREATE);
return Response.status(200).entity("Uploaded file name : " + fileName).build();
} catch (Exception e) {
e.printStackTrace();
}
}
return Response.status(200).entity("Uploaded file name : " + fileName).build();
}
我还引用了以下链接。
MultipartBody
的单独类,我可以生成 swagger UI与
@Schema(type = SchemaType.STRING, format = "binary") and @PartType(MediaType.APPLICATION_OCTET_STREAM)
注解。但我的要求是只使用
MultipartFormDataInput
.
最佳答案
你快到了 :) 只需在你的 RequestBody/Schema 中使用一个专用类并告诉 OpenAPI 忽略你的方法的参数。
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@RequestBody(content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA,
schema = @Schema(implementation = MultipartBody.class))
)
@Operation(operationId = "uploadFile")
public Response uploadFile(@Parameter(hidden = true) MultipartFormDataInput input) {
//... your logic here
}
需要注意的两点:
@Parameter(hidden = true)
告诉 Smallrye OpenAPI 不要考虑你的
MultipartFormDataInput
生成 Schema 模型时。然后你需要使用
@RequestBody
明确地告诉描述模式,其中
MultipartBody
是一个描述所有输入参数的类(如果你想传递其他 Prop 以及文件有效负载,你可以在那里添加更多参数)
public class MultipartBody {
@FormParam("file")
@Schema(type = SchemaType.STRING, format = "binary", description = "file data")
public String file;
@FormParam("fileName")
@PartType(MediaType.TEXT_PLAIN)
public String fileName;
}
只要确保
@FormParam
MultipartBody
中的注释字段匹配您希望在
MultipartFormDataInput
中找到的 ,,parts"- 例如,在您的情况下,文件属性应该具有
@FormParam("attachment")
关于java - 如何使用 Quarkus 在 RestEasy 中为 MultipartFormDataInput 提供 swagger 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64079847/
我已经使用 将资源添加到类路径中 -H:IncludeResources=.*/kubernetes_auth.crt$ -H:Log=registerResource:verbose 当我构建图像时
我正在阅读 Quarkus documentation about configuration ,这引起了我的注意: Quarkus does much of its configuration an
我有一系列简单的链式操作,它们使用在 Quarkus 服务中运行的 Panache 存储库检索和保存一些数据。这些操作并行化的地方是 ContextNotActiveException被抛出。在删除并
我最近开始在我的 Quarkus 网络应用程序中使用 testcontantainers 进行单元/集成测试数据库操作。它工作正常,除了我想不出在 quarkus.datasource.url 应用程
我想更改 Quarkus 应用程序的日志记录级别。 如何从配置文件或在运行时执行此操作? 最佳答案 控制根日志记录级别的属性是 quarkus.log.level (默认为 INFO )。 此属性可以
我正在寻找一种方法来在运行时更改 Quarkus 应用程序 (JVM) 的一个或多个类/包的日志级别。是否有我可以用来以编程方式更改级别的 API,例如通过公开 REST API 还是已经存在其他解决
我已经使用 Quarkus 开发模式 ( mvn quarkus:dev ) 启动了我的应用程序,我希望能够调试它。 怎么能这样? 最佳答案 只需使用 mvn quarkus:dev 启动 Quark
在我当前的项目中,我们将用户登录信息存储在 MongoDB 集合中。我们希望实现一种身份验证机制,根据存储在所述 MongoDB 中的信息检查请求中的凭据。有一个教程可以做到这一点with JPA +
我的 application.properties 文件中有一些配置: ... quarkus.datasource.url=jdbc:postgresql://...:5432/.... quark
在夸库斯 Application Configuration Guide它提到了如何使用配置文件配置应用程序(例如%dev.quarkus.http.port=8181)。 但是有没有办法访问配置文件
我希望我的 Quarkus 应用程序在默认端口以外的端口上运行。我怎样才能做到这一点? 最佳答案 要使用的 Quarkus 配置属性是 quarkus.http.port(默认值为 8080)。如果在
Quarkus getting started unittest描述如何模拟注入(inject)的服务。然而,当尝试将此应用于注入(inject)的休息客户端时,这似乎不起作用。 在我的应用程序中,要
我曾尝试在 Quarkus 中添加 logback,但后来发现 Quarkus 不支持 logback。如果我错了,我可以通过示例知道如何在 Quarkus 中配置 logback 吗?提前致谢。 最
在使用 Quarkus Restclient/RESTEasy 进行集成测试时,我们希望在运行时覆盖 url 和端口。这样做的原因是,如果我们并行构建多个模块,我们需要使用随机端口,否则我们会遇到端口
我正在尝试将 JEE 服务迁移到 Quarkus想知道如何在 Quarkus 应用程序中获取线程工厂。只需创建一个像 javaExecutors.defaultThreadFactory();就像在
我正在使用 quarkus 1.2.0。 一般: 客户端浏览器向服务器请求数据。服务器(Quarkus 应用程序)正在从客户端接收 UTC 时间。 (ok) 现在服务器应该将数据库中的数据与客户端浏览
我试图找到一种方法如何在 quarkus DI 中以编程方式创建 bean,但没有成功。在这个框架下可以吗?看来BeanManager尚未实现所需的方法。 最佳答案 首先,我们应该澄清“以编程方式创建
我创建了以下调用类,当调用拦截的方法时,应该调用它: import javax.interceptor.AroundInvoke; import javax.interceptor.Intercept
我正在尝试将多模块 Maven 项目从普通 Java EE 8 转换为 Quarkus,并且 ArcAnnotationProcessor 似乎会抛出有关引用位于不同位置的依赖项的所有注入(injec
我们如何在 Quarkus 中使用 jasypt 加密和解密属性文件中的数据库密码。解密将在加载或启动应用程序时发生。请分享您对此的意见或想法。 @chrisgleissner 非常感谢任何帮助。 应
我是一名优秀的程序员,十分优秀!