https://avatars.githubusercontent.com/u/6058558

程式狂想筆記

CSP 網頁安全性設計

最近把一個專案上到測試環境,明明網站是 http 環境,但是裡面網址竟然顯示 https,我查看原始碼也沒強制加 https,也沒有用<base>改變程式基本位置。

MultipartFile.transferTo 遇到 FileNotFoundException 問題

之前公司同事有教,在 Window 在專案 D 朝設定 /app/file(參照位置),執行時候就會吃D:/app/file。這個非常實用,不需要再重新配置。

但在用 Spring Boot 會發生讀不到檔案。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
    @Override
    public String store(MultipartFile file, String fileName) throws IOException {

        String destPath "/app/file/";
        File filePath = new File(destPath);
        File dest = new File(filePath, fileName);
        if (!filePath.exists()) {
            filePath.mkdirs();
        }
        try {
            file.transferTo(dest);
            log.info("file save success");
        } catch (IOException e) {
            log.error("File upload Error: ", e);
            throw e;
        }
        return dest.getCanonicalPath();
    }