如何使用内存文件中的顶点创建可下载文件 api
How to create downloadable file api with vertx in memory files
我从 S3 下载文件并通过将其转换为字节数组将它们保存在内存中。
我不明白如何获取此字节数组并使用 vertx.
创建下载 api
这是我卡住的地方:
router.get("/api/download/:requestId").handler(this::downloadFile);
private void downloadSimulatorFile(RoutingContext routingContext) {
String requestId = routingContext.request().getParam("requestId");
JsonObject response = new JsonObject();
try {
byte [] array=downloadFileFromS3ByRequestId(requestId);
} catch (Exception e) {
log.error(e);
} finally {
routingContext.response()
.putHeader("content-type", "application/json")
.sendFile(..)
// here is where i stuck as sendFile only expects
Strings which symol path to a file
}
}
如何在不保存文件并将其保存在内存中的情况下修改它?
谢谢
我试过了,效果很好:
req.response()
.putHeader("Content-Type", "application/json")
.end(Buffer.buffer(bytes));
用于将 xlsx 文件作为字节数组发送到 vertx
byte [] array=downloadFileFromS3ByRequestId(requestId);
response.putHeader(io.vertx.core.http.HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=file.xlsx");
response.putHeader(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_OCTET_STREAM);
response.end(Buffer.buffer(array));
我从 S3 下载文件并通过将其转换为字节数组将它们保存在内存中。 我不明白如何获取此字节数组并使用 vertx.
创建下载 api这是我卡住的地方:
router.get("/api/download/:requestId").handler(this::downloadFile);
private void downloadSimulatorFile(RoutingContext routingContext) {
String requestId = routingContext.request().getParam("requestId");
JsonObject response = new JsonObject();
try {
byte [] array=downloadFileFromS3ByRequestId(requestId);
} catch (Exception e) {
log.error(e);
} finally {
routingContext.response()
.putHeader("content-type", "application/json")
.sendFile(..)
// here is where i stuck as sendFile only expects
Strings which symol path to a file
}
}
如何在不保存文件并将其保存在内存中的情况下修改它?
谢谢
我试过了,效果很好:
req.response()
.putHeader("Content-Type", "application/json")
.end(Buffer.buffer(bytes));
用于将 xlsx 文件作为字节数组发送到 vertx
byte [] array=downloadFileFromS3ByRequestId(requestId);
response.putHeader(io.vertx.core.http.HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=file.xlsx");
response.putHeader(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_OCTET_STREAM);
response.end(Buffer.buffer(array));