Is it possible to set the file name?
I found an article , but the method that is in it does not work. Still saves with the name that is stored on the server. Is there another way? Demo

    2 answers 2

    This is a very fresh opportunity, it works somehow, better make a script that you will give the path to the file with and the desired name at the entrance, and there in the old way through the "Content-Disposition".

    • And you can link to an example? - hog

    Reliable to do this on the client can not be, according to current standards. The file name is answered by the HTTP Header Content-Disposition , which is generated by the server to which the link leads.

    What can be done:

    1) Put down the download tag and hope it works in some browsers.

    2) Try to download the file using XHR2 , create a new link to the downloaded file. Once this hack worked in the FF and Chrome.

     window.URL = window.URL || window.webkitURL; var xhr = new XMLHttpRequest(), a = document.createElement('a'), file; xhr.open('GET', 'someFile', true); xhr.responseType = 'blob'; xhr.onload = function () { file = new Blob([xhr.response], { type : 'application/octet-stream' }); a.href = window.URL.createObjectURL(file); a.download = 'someName.gif'; // Можно проставить любое имя a.click(); }; xhr.send();