ianchoi

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

  •  
  •   ianchoi · Jan 16, 2023 · 1524 views
    This topic created in 1244 days ago, the information mentioned may be changed or developed.
    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 replies    2023-01-17 15:20:48 +08:00
    DingJZ
        1
    DingJZ  
       Jan 16, 2023
    是不是和平台相关,我用 mac 的 chrome 这段代码粘到控制台下载是没问题的,是 pem 格式
    horseInBlack
        2
    horseInBlack  
       Jan 16, 2023
    Windows + edge 下载的也是 pem
    julyclyde
        3
    julyclyde  
       Jan 17, 2023
    你这个 URL 不带扩展名,也没有带 content disposition header 吧,所以存盘的时候用什么扩展名,其实是由浏览器根据 MIME 脑补的?
    ianchoi
        4
    ianchoi  
    OP
       Jan 17, 2023
    @DingJZ 我在 Chrome 试了也是 pem 格式,但开发是用 react + antd 的环境
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1051 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 23:02 · PVG 07:02 · LAX 16:02 · JFK 19:02
    ♥ Do have faith in what you're doing.