Vertx FileUpload上传不带扩展名的文件 [英] Vertx FileUpload uploads file without extension

查看:614
本文介绍了Vertx FileUpload上传不带扩展名的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vertx-web并尝试上传文件.这是我的代码:

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.

文件上传名称:logo.png

文件保存的名称:45edd7b4-5287-4fba-927e-f256f4b09aea

我希望上传的文件扩展名和内容类型保持原样.

I want the uploaded file extension and the content-type to remain as it is.

推荐答案

您无法配置BodyHandler来执行此操作.它使用唯一标识符的原因是为了避免名称冲突.

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.

这篇关于Vertx FileUpload上传不带扩展名的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆