学无先后,达者为师

网站首页 编程语言 正文

根据文件后缀名称获取contentType,其中Minio上传文件会用到contentType

作者:明快de玄米61 更新时间: 2023-07-07 编程语言

代码:

import org.springframework.http.MediaType;
import org.springframework.http.MediaTypeFactory;

public class Test {

    public static void main(String[] args) {
        String fileName = "1.docx";
        String contentType = MediaTypeFactory.getMediaType(fileName).orElse(MediaType.APPLICATION_OCTET_STREAM).toString();
        System.out.println("文件名称为“" + fileName + "”的contentType:" + contentType);
    }
}

结果:

文件名称为“1.docx”的contentType:application/vnd.openxmlformats-officedocument.wordprocessingml.document

原文链接:https://blog.csdn.net/qq_42449963/article/details/129799820

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新