当前位置:   article > 正文

Fetch调用接口转blob格式下载_fetch blob

fetch blob

  1. fetch('https://example.com/api/download', {
  2. method: 'GET',
  3. headers: {
  4. 'Content-Type': 'application/json',
  5. },
  6. })
  7. .then(response => response.blob())
  8. .then(blob => {
  9. const url = window.URL.createObjectURL(blob);
  10. const a = document.createElement('a');
  11. a.href = url;
  12. a.download = 'file.pdf';
  13. document.body.appendChild(a);
  14. a.click();
  15. window.URL.revokeObjectURL(url);
  16. });

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
  

闽ICP备14008679号