ianchoi

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

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