zoukankan      html  css  js  c++  java
  • 后端返回文件流,前端blob下载

    后端

    return response()->download(storage_path('app/public').$file,$filename,array(
                        'Content-Type' => 'application/pdf',
                    ));

    前端:

    downloadPage(id){
          webServices.post('downPage',{"id":id},{responseType:'arraybuffer'}).then((res)=>{
            let blob = new Blob([res.data], { type: "application/pdf" });
            const elink = document.createElement('a')
            elink.download = 'testPage.pdf';
            elink.style.display = 'none'
            elink.href = URL.createObjectURL(blob)
            document.body.appendChild(elink)
            elink.click()
            URL.revokeObjectURL(elink.href) // 释放URL 对象
            // this.downLoading = false
            document.body.removeChild(elink)
    
          });
        },
    {responseType:'arraybuffer'}这个一定要传,不然下载的文件就是空白文件
    踩过这个坑,还有下一个坑等着你,这一路就是给自己填坑,坑填多了,也就习惯了,直到这一路平坦了,也就无怨无悔了。
  • 相关阅读:
    qt 计时器自动刷新图片
    qt读取文本
    QLable 显示图片
    QButtonGroup 的使用
    Qt乱码的问题
    wpf 依赖强制回调
    实现Button的动态响应
    C# 闭包对像
    2020新年目标
    捕获、冒泡与阻止事件传播
  • 原文地址:https://www.cnblogs.com/xiaofeilin/p/14087440.html
Copyright © 2011-2022 走看看