UnsupportedOperationException in vert.x/netty fileupload

Viewed 31

I am trying to upload a file using vert.x[3.9.8] but for large files [1GB+] i keep getting below error.The file is being uploaded correctly. Whats the issue i am running into. Is this a Netty version clash with Vert.x?

[2022-09-05 14:40:30 +0530][io.vertx.core.impl.ContextImpl] SEVERE: Unhandled exception 
java.lang.UnsupportedOperationException
    at io.vertx.core.http.impl.NettyFileUpload.definedLength(NettyFileUpload.java:179)
    at io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder.loadDataMultipartOptimized(HttpPostMultipartRequestDecoder.java:1188)

    public void helidonToVertxTest(TestContext testContext) {
                Async fileSentAsync = testContext.async();
                Async fileReceivedAsync = testContext.async();
                Router router = Router.router(vertx);
                router.route().handler(BodyHandler.create());
                router.post("/api/upload").handler(routingContext -> {
                    System.out.println("File/s has been received.");
                    routingContext.response().end();
                    testContext.assertEquals(1, routingContext.fileUploads().size());
                    Iterator<FileUpload> iterator = routingContext.fileUploads().iterator();
                    FileUpload artifact = iterator.next();
                    Path savedArtifactsPath = Paths.get(artifact.uploadedFileName());
                    System.out.println("Uploaded file is "+savedArtifactsPath);
                    testContext.assertTrue(savedArtifactsPath.toFile().exists());
                    fileReceivedAsync.complete();
                });
            
                vertx.createHttpServer().requestHandler(router).listen(8080, listenResult -> {
                    if (listenResult.failed()) {
                        System.out.println("Could not start HTTP server");
                        listenResult.cause().printStackTrace();
                    } else {
                        System.out.println("Server started");
                        Path tempFile = createTemporaryFile();
                        String filename = "C:\\Users\\ansgupgu\\Pictures\\Movies\\cp.mp4";
                        sendFileHelidonUsingMultipart(fileSentAsync, Path.of(filename));
                    }
                });
                fileSentAsync.await(60*1000);
                fileReceivedAsync.await(60*1000);
            }

1 Answers

Netty 4.1.69.Final and later calls definedLength(). Vert.x 3.9.10 changes definedLength()'s implementation from throw new UnsupportedOperationException() to an actual calculation. So you'll want to use Vert.x 3.9.10 or later with Netty 4.1.69.Final or later.

Related