About downloading the specified file locally from node to the front end

requirements are as follows:

  1. the front end selects a file name to pass parameters to node
  2. first download the data to the Java backend through the post request (plus token) and save it to node (at this time, the file format is zip)
  3. send the downloaded file to the front end from node, and download the front end

questions are as follows:

now that you have implemented 1 and 2, when you try to implement 3, refer to the". / public/ resource name configured in the parameter download in res.dowload (),. The suffix "does not quite understand who this relative path is. Although the download resource of a tag is simulated in the reference example, it is still too clear about the logic. Please do not hesitate to give us advice on orz

.

the code is as follows:

var express = require("express");
router.get("/xxx", function(req, res){
  res.download("public/xx.xx");
});

the third requirement is to realize that the front-end chrome can call up its own downloader to download files locally to client. It is best to achieve one-step real-time download through pipe, instead of completing the transfer and then starting the front-end download. Mainly do not understand how to achieve this step through download

there may be some problems with the expression. Please take care of orz.

Feb.22,2022

download is used to download local files
you just string the java stream with your corresponding stream


the current solution is
1. After the post request, download the file locally in node and return it to the front-end path and file name,
2. After the front end splices the get request link, simulate the a tag click to download
3.Node receives the get request to execute the download
in which the key code to simulate the a tag click is as follows:

path = file+'?dir='+response.data.dir+'&name='+response.data.fileName;  
console.log(path) 
let a = document.createElement('a');
a.href = path;
a.download = response.data.fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3561d-34357.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3561d-34357.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?