以流的方式下载文件

封装的axios下载

// 下载数据
export const downloadFile = (id) => {
  return axios.request({
    url: ‘/file-manage/file/download/‘ + id,
    method: ‘get‘,
    responseType: ‘blob‘
  })
}

传入下载的文件名,对应的文件id来下载流格式的文件

    // 下载文件
    downloadFile (filename, id) {
      downloadFile(id).then(res => {
        console.log(res)
        if (!res) {
          return
        }
        let url = window.URL.createObjectURL(res.data)
        let link = document.createElement(‘a‘)
        link.style.display = ‘none‘
        link.href = url
        link.setAttribute(‘download‘, filename)
        document.body.appendChild(link)
        link.click()
      }).catch(err => {
        console.log(err.message)
      })
    },

原文地址:https://www.cnblogs.com/ronle/p/11031230.html

时间: 2024-08-02 10:33:07

以流的方式下载文件的相关文章

文件流的方式下载文件

//流方式下载 protected void Button4_Click(object sender, EventArgs e) { string fileName = "aaa.zip";//客户端保存的文件名 string filePath = Server.MapPath("DownLoad/aaa.zip");//路径 //以字符流的形式下载文件 FileStream fs = new FileStream(filePath, FileMode.Open);

asp.net已流的方式下载文件

string filePath = context.Server.MapPath("~/" + uploadFolder+"/"+file_name);//路径 System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath); if (fileInfo.Exists == true) { //以字符流的形式下载文件 FileStream fs = new FileStream(filePath, File

C# Http方式下载文件到本地

下文代码是从网络(http://www.cnblogs.com/hayden/archive/2012/04/26/2472815.html)得来,亲测好用.我中修改了下格式和注释,版权属于原作者. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Net; namespace ConsoleTest { class

返回流的形式下载文件

//下载文件 private void Down(HttpContext context) { string filePath = context.Request["url"]; if (!string.IsNullOrEmpty(filePath)) { string customFileName = DateTime.Now.ToString("yyyyMMddHHmmss");//客户端保存的文件名 using (FileStream fileStream =

java通过http方式下载文件

package com.qiyi; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URL; import java.net.URLConnection; import java.util.List; import java.util.Map; import java.io

重载Python FTP_TLS 实现Implicit FTP Over TLS方式下载文件

对于Python2.7来说,内置的FTP_TLS类并不支持Implicit FTP Over TLS加密方式的FTP Server操作,为支持Implicit FTP Over TLS加密方式,必须重载内置的FTP_TLS类,具体代码如下: import ftplib class FTP_TLS(ftplib.FTP_TLS): def __init__(self, host='', user='', passwd='', acct='', keyfile=None, certfile=None

ajax方式下载文件

<button type="button" onclick="download()">导出</button> function download() { var url = 'download/?filename=aaa.txt'; var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); // 也可以使用POST方式,根据接口 xhr.responseType = "b

C#利用WebClient 两种方式下载文件

WebClient client = new WebClient(); 第一种 string URLAddress = @"http://files.cnblogs.com/x4646/tree.zip"; string [email protected]"C:\"; client.DownloadFile(URLAddress, receivePath + System.IO.Path.GetFileName(URLAddress)); 就OK了. 第二种 Str

以文件流的方式 文件上传 下载

HTML: <div class="box-body">                                    <form id="upload_form" enctype="multipart/form-data"  action="/wjgl/fileSave" method="post">