英文:
Vertx Streaming csv file/data to http response
问题
以下是您要翻译的内容:
我想在Vertx API响应中将一些数据作为CSV文件返回给DB。我一直在遵循此链接,但我无法返回正确的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();});
英文:
I want to return some data from DB as a CSV file in the vertx API response. I have been following this link
But I'm not able to return proper CSV file as API response.
My code:
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();});
答案1
得分: 1
你遇到了什么错误/行为?
尝试使用来自CSV文件的字节创建缓冲区。
byte [] csvBytes = <一些从结果集中提取表示CSV文件的字节的方法>
response.end(Buffer.buffer(csvBytes));
英文:
What kind of error/behavior are you getting?
Try creating a Buffer with the bytes from the CSV file.
byte [] csvBytes = <some method extracting the bytes representing the csv file from the result set>
response.end(Buffer.buffer(csvBytes));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论