vertx 3 - Upload stream to S3

698 views
Skip to first unread message

Tiago Reis

unread,
Aug 10, 2015, 1:29:56 PM8/10/15
to vert.x
Hi,

I'm trying to write code that pushes a stream to s3 using the rest api. The implementation is inspired on one that I saw here on this groups for vertx 1.x. 

The authentication part works fine because I'm able to put something like this:

// S3ClientRequest.java
public S3ClientRequest createPutRequest(String bucket, String key, Handler<HttpClientResponse> handler) {
        HttpClientRequest httpRequest = client.put("/" + key, handler);
        return new S3ClientRequest("PUT", bucket, key, httpRequest, awsAccessKey, awsSecretKey);
}

...
// S3Client.java
public void put(String bucket, String key, Buffer data, Handler<HttpClientResponse> handler) {
        S3ClientRequest request = createPutRequest(bucket, key, handler);
        request.end(data);
}
...
// main verticle
Buffer toUpload = Buffer.buffer("upload this to s3");
final S3Client s3Client = new S3Client("private", "thingie");
        s3Client.put("bucketname", "key", toUpload, response -> {
             int status = response.statusCode();
});



But if I try to use a Pump like so:

// S3Client.java
public void put(String bucket, String key, HttpServerFileUpload upload, Handler<HttpClientResponse> handler) {
    S3ClientRequest request = createPutRequest(bucket, key, handler); // same method as above
    Pump pump = Pump.pump(upload, request);
    pump.start();
}

...
// main verticle
requestEvent.uploadHandler(fileUploadEvent -> s3Client.put("bucket", "mykey",
           fileUploadEvent, awsResponseEvent -> {
                    int status = awsResponseEvent.statusCode();
                }));




So basically what I'm trying to do is use the Pump to get the HttpServerFileUpload data to be pumped to the S3 request, but that is never happening and my end handler is only called when the timeout occurs. I can see the chunks being written but the end methods are on my S3ClientRquest are never called, I was expecting the Pump to deal with it.
 
If it doesn't, how can I know that the pump finished pumping all the data?

thanks
 

Tiago Reis

unread,
Aug 11, 2015, 3:17:51 AM8/11/15
to vert.x
Anyone has any idea? I really wanted to avoid having to store the file on the server even if temporarily.

Please let me know if any extra information about the code, or more code, would be helpful.

thanks

Tim Fox

unread,
Aug 11, 2015, 3:21:42 AM8/11/15
to ve...@googlegroups.com
Add an end handler on the HttpServerFileUpload, and when that is invoked call end on the client request.


thanks
 
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/508b8d91-dd15-4e4f-9eb8-e6f6e4347555%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tiago Reis

unread,
Aug 11, 2015, 11:40:35 AM8/11/15
to vert.x
thanks Tim.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages