
const key = ` ---start--- xxxxxxx ---end--- ` const blob = new Blob([key], { type: 'application/x-pem-file', }) const a = document.createElement('a') a.href = window.URL.createObjectURL(blob) a.download = 'key.pem' a.style.isplay = 'none' document.body.appendChild(a) a.click() 大概代码如上,key 是 String 格式
下载完文件格式就变成 key.cer
求解
1 DingJZ 2023-01-16 16:50:37 +08:00 是不是和平台相关,我用 mac 的 chrome 这段代码粘到控制台下载是没问题的,是 pem 格式 |
2 horseInBlack 2023-01-16 16:59:43 +08:00 Windows + edge 下载的也是 pem |
3 julyclyde 2023-01-17 14:07:59 +08:00 你这个 URL 不带扩展名,也没有带 content disposition header 吧,所以存盘的时候用什么扩展名,其实是由浏览器根据 MIME 脑补的? |