1

我想在 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();});
4

1 回答 1

1

你得到什么样的错误/行为?

尝试使用 CSV 文件中的字节创建一个缓冲区。

byte [] csvBytes = <some method extracting the bytes representing the csv file from the result set>

response.end(Buffer.buffer(csvBytes));
于 2020-08-09T11:46:46.100 回答