我想在 vertx API 响应中将 DB 中的一些数据作为 CSV 文件返回。我一直在关注这个链接
但我无法返回正确的 CSV 文件作为 API 响应。
我的代码:
rc.response()
.putHeader("Content-Type", "application/csv")
.putHeader("Content-Disposition", "attachment; filename=stream_wide.csv")
.putHeader(HttpHeaders.TRANSFER_ENCODING, "chunked")
.setChunked(true);
getDataFromDB()
.subscribe(
rs -> rc.response().write(rs, "UTF-8"),
ex -> {ex.printStackTrace(); logger.error("exception encountered " + ex.getMessage());},
() -> {rc.response().end(); rc.response().close();});