Can js adjust the pop-up window of the system to select the download path when downloading the file?

recently, there is a requirement in the project that when the download button is clicked in the browser, the dialog box of which path to download the file will pop up. May I ask whether this function js can be realized by calling some API

Apr.01,2021

this is related to your phone and browser.
some may ask you to confirm the save location, and some may be saved directly to the default location


none. Js cannot operate the file system in the web page


this is determined by the browser, such as chrome default user download directory. There is no need to confirm
other browsers. Some browsers can choose their own save location when downloading


this pop-up box is not implemented by which interface js calls. The appearance of the pop-up box is the behavior of the browser, which is usually implemented through the back-end.
take java as an example, click the "download" button to send a download request to the server, and the server accepts the request and processes it. The key point is that when the server finishes processing and sends response, to the front end, it needs to set the header of a specific response (I feel that the dialog box with information such as selecting a path appears in the browser is judged according to this header, pure personal guess, and some people know it accurately. Welcome to leave a message)
the core code looks like this:

//ContentType
  response.setContentType("application/octet-stream; charset=utf-8");
//
  String fileName=new String(file.getName().getBytes("utf-8"),"ISO-8859-1");
  response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
  IOUtils.copy(new FileInputStream(file), response.getOutputStream());

I have written the download file before, and the browser needs to pop up the download box. At first, I was obsessed with how the download box appeared. Later, I found that my point was wrong, and finally I used the above code to achieve it. I hope it will be helpful

Menu