java通过postman上传MultipartFile格式文件

2021/5/1 12:56:46

本文主要是介绍java通过postman上传MultipartFile格式文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、Controller类代码

/**
     * 上传MP4格式视频
     */
    @RequestMapping("/VideoMps4")
    @ResponseBody
    public Object VideoMps4(@RequestParam MultipartFile file) {
        try {
            String fileName = file.getOriginalFilename();
            if (fileName.equals("TestPush.map")) return "succeed";
            //获取mp4文件名
            String fileJc = fileName.substring(0, fileName.lastIndexOf("."));
            //添加文件名
            Long prefix = 10000000L;
            //日期文件名
            String foldPath = "/ceshi/" + "2021429" + prefix;
            //这里改你挂载的NFS网盘
            String dataFold = "D:\\\\web\\\\data\\\\";
            //存放路径
            String targetFolderPath = dataFold + foldPath;
            File foldFile = new File(targetFolderPath);
            //为空建立一个的文件夹
            if (!foldFile.exists()) {
                foldFile.mkdirs();
            }
            //视频命名
            String newFileName = " i like China.mp4";
            String filePath = dataFold + foldPath + "/" + newFileName;
            File locaFile = new File(filePath);
            file.transferTo(locaFile);
            return "succeed";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

二、application.properties配置文件

#上传文件的大小
spring.http.multipart.maxFileSize = 20MB

三、postman
在这里插入图片描述

四、运行
在这里插入图片描述
本文到这里就结束了,有问题欢迎来讨论。



这篇关于java通过postman上传MultipartFile格式文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程