1. 程式人生 > 其它 >JAVA上傳檔案或視訊到掛載的NFS網路資料夾、網盤

JAVA上傳檔案或視訊到掛載的NFS網路資料夾、網盤

一、首先確定NFS已經成功掛載到你的電腦
可以參考:https://blog.csdn.net/fo_xi/article/details/116322816
二、下面演示上傳一個MP4格式視訊
1、工具類

    @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進行測試的,具體測試步驟連線:https://blog.csdn.net/fo_xi/article/details/116325569