Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用vertx内存文件创建可下载的文件api_Java_Vert.x - Fatal编程技术网

Java 如何使用vertx内存文件创建可下载的文件api

Java 如何使用vertx内存文件创建可下载的文件api,java,vert.x,Java,Vert.x,Iam从S3下载文件,并通过将其转换为字节数组将其保存在内存中。 我不明白如何使用这个字节数组并使用vertx创建下载api 这就是我坚持的地方: router.get("/api/download/:requestId").handler(this::downloadFile); private void downloadSimulatorFile(RoutingContext routingContext) { String requestId = rout

Iam从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));

用于在vertx中将xlsx文件作为字节数组发送

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));

为什么不将下载文件转换成流并发送该流作为响应。你知道怎么做吗?