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
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
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
Previous: What are the questions about the usefulness of pass statements in python3?
Next: Element, how to understand this code? Span and offset what does that mean?
do the gods have plug-ins for uploading attachments in the mobile version that can also be uploaded more than one? ...
the traditional position: fixed; is relative to the window, and there are two main points of the problem . relative to the specified parent element fixed positioning encountered the following problems in mobile development. The green box is the...
better-scroll, can be delimited infinitely, how to solve this bug ...
how can the data looped out by vue change color to the current one when clicked? this is what my page says <ol v-if="tooglezhi" class="ol_one"> <li v-for="(item,key) in arr" ...
the number of digits in the input box is controlled. When this value echoes the maximum number of digits, the input can only be deleted and the input cannot be overridden directly. who knows what attributes the input has to control this ...
Baidu didn t find the reason for it for a while-the error message thrown by the browser was Uncaught Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead or wr...
< html > <ion-list> <ion-item *ngFor= let i of list >< ion-item> < ion-list> < html > how do I listen to whether ngFof has finished traversing this array? ...
as shown in the figure, there are four sort buttons in a table header, and the requirements are as follows: the first click on descending order, the second click on ascending order, and the third click on the default display (no sorting); I would li...
shouldn t vue use vue-router? Why can it only be put into devDependencies (development dependency)? ...
<el-select @change="orgChange" v-model="sectionNameOpt" filterable placeholder=""> <el-option v-for="item in sectionNameOpts" :key="item.index" :label="item.orgN...
the XMLHttpRequest that requests the interface to keep reporting url (interface) under IE edge ie10 requires cross-domain resource sharing CORS, but the data is all back. Other browsers are fine, the background should have done cors processing, why? ...
how to set path to window.loaction.host with jquery.cookie.js under IE cannot be saved, how to set path ...
question, as shown in figure the html code is as follows: <span class="button"><input type="file" id="file" name="file" onchange="this.parentNode.nextSibling.value = this.value">< sp...
I have two elements, a parent element and a child element. the parent element rotates N degrees. then I want to move the positioning of the child element, which moves relative to the parent element. how do I calculate the offset value. Let it move re...
I just want to install jquery, with yarn. Why do I install so many other things? ...
directly above the picture, how to take this top value ...
as shown in the figure, v-for generates input, in Vue. When the add button is clicked, the cursor automatically focuses on the latest input, window and automatically moves to the appropriate location! ...
problem: the IOS system entered the page for the first time and added if (navigator.geolocation) {}, but did not execute navigator.geolocation.getCurrentPosition (this.showPosition.bind (this), this.showError.bind (this), options); did not enter showPo...
found a JS scheme that uses canvas to generate thumbnails on the Internet, which can generate thumbnails, but in some cases, the generated thumbnails are black and you can t see what the original thumbnails look like. Because the previous paragraph is ...
...