Quarkus端点下载和上传json文件



我必须创建端点来下载和上传组配置作为json文件。在数据库中,配置被保存为json对象。如果用户想要下载配置,它应该转换为json文件。如果用户上传配置文件,它应该转换为json对象,这样它可以保存在数据库中。

@GET
@Path("group/config/{groupId}")
@Produces(MediaType.APPLICATION_JSON)
public Response downloadGroupConfig(@PathParam("groupId") String groupId) {
// the group config comes from database and should be converted here to config.json file and then added to response      
// something like: return Response.ok(config.json).build();
}

和用于上传配置文件

@POST
@Path("group/config/{groupId}")
@Produces(MediaType.APPLICATION_JSON)
public Response uploadConfigFile(@RequestBody //(contains config.json), @PathParam("groupId") String groupId ){
// convert config.json to json object and save it in database
}

对于下载,您可以这样做:

@GET
@Path("group/config/{groupId}")
@Produces(MediaType.APPLICATION_JSON)
public Response downloadGroupConfig(@PathParam("groupId") String groupId) {
return Response.ok("{"location":  "German"}")
.header("Content-Disposition", "attachment;filename="config.json"")
.build()
}

对于上传部分,您可能希望使用Multipart支持,参见此。

最新更新