2017-07-27 2 views
1

Iam lädt Dateien von S3 herunter und speichert sie im Speicher, indem sie in Byte-Arrays konvertiert werden. Ich verstehe nicht, wie kann ich dieses Byte-Array nehmen und ein Download-API mit Vertex erstellen.So erstellen Sie eine herunterladbare Datei api mit vertx in Speicherdateien

hier ist, wo ich stecken:

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 

      } 
    } 

Wie kann ich das ändern, ohne die Datei zu speichern und halten Sie sie im Speicher?

Dank

+0

Warum Sie Ihre Download-Datei in Strom umwandeln Dont und diesen Strom als Antwort senden. –

+0

eine Idee, wie man das macht? – rayman

Antwort

1

Ich versuchte es, und es funktioniert:

req.response() 
    .putHeader("Content-Type", "application/json") 
    .end(Buffer.buffer(bytes)); 
Verwandte Themen