サーバーからファイルをダウンロードしたいのですが、downloadする際ファイルの名前を変更したいのですがどうすればよろしいでしょうか
jquery
1 2 var fileName = "test.mp4" 3 var outputFIle = "test_out.mp4" 4 var downloadUrl = url + "/" + outputFile; 5 6 var xhr = new XMLHttpRequest(); 7 xhr.open('GET' , downloadUrl , true); 8 xhr.responseType = 'blob'; 9 10 xhr.onload = function (e) { 11 if (this.status == 200) { 12 var blob = this.response; 13 14 if (navigator.appVersion.toString().indexOf('.NET') > 0) { 15 window.navigator.msSaveBlob(blob, outputFile); 16 } else { 17 18 var a = document.createElement("a"); 19 20 var blobUrl = window.URL.createObjectURL(new Blob([blob], { 21 type: blob.type 22 })); 23 24 document.body.appendChild(a); 25 a.style = "display: none"; 26 27 a.href = blobUrl; 28 29 a.download = outputFile; 30 //最終的にダウンロードした際の名前を"filename"にしたい 31 //現状"outputFile"の名前でダウンロードされる 32 a.click(); 33 } 34 } 35 }; 36 37 xhr.send();
質問タグとタイトルの jquery は使用していないようなのではずしてください。質問タグは「JavaScript」が妥当だと思います。