V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ianchoi
V2EX  ›  前端开发

前端| pem 格式用 a 标签下载变成 cer 格式问题

  •  
  •   ianchoi · 2023-01-16 14:26:41 +08:00 · 617 次点击
    这是一个创建于 456 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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.display = 'none'
    document.body.appendChild(a)
    
    a.click()
    

    大概代码如上,key 是 String 格式

    下载完文件格式就变成 key.cer

    求解

    4 条回复    2023-01-17 15:20:48 +08:00
    DingJZ
        1
    DingJZ  
       2023-01-16 16:50:37 +08:00
    是不是和平台相关,我用 mac 的 chrome 这段代码粘到控制台下载是没问题的,是 pem 格式
    horseInBlack
        2
    horseInBlack  
       2023-01-16 16:59:43 +08:00
    Windows + edge 下载的也是 pem
    julyclyde
        3
    julyclyde  
       2023-01-17 14:07:59 +08:00
    你这个 URL 不带扩展名,也没有带 content disposition header 吧,所以存盘的时候用什么扩展名,其实是由浏览器根据 MIME 脑补的?
    ianchoi
        4
    ianchoi  
    OP
       2023-01-17 15:20:48 +08:00
    @DingJZ 我在 Chrome 试了也是 pem 格式,但开发是用 react + antd 的环境
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1049 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:13 · PVG 03:13 · LAX 12:13 · JFK 15:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.