问题
I am using vertx-web
and trying to upload file. Here is my code:
router.route().handler(BodyHandler.create().setUploadsDirectory("some/path/uploads"));
router.post("/api/upload").handler(routingContext -> {
for(FileUpload f : routingContext.fileUploads()){
System.out.println(f.fileName()); // logo.png
}
routingContext.response().end()
});
Above code, uploads file to the given path, but the uploaded file extension is missing.
File upload name: logo.png
File saved name: 45edd7b4-5287-4fba-927e-f256f4b09aea
I want the uploaded file extension and the content-type to remain as it is.
回答1:
You can't configure the BodyHandler
to do this. The reason why it uses unique identifiers is to avoid name collisions.
You can move the file to another directory with a proper name.
来源:https://stackoverflow.com/questions/46189571/vertx-fileupload-uploads-file-without-extension