0
如何從服務器上的公共可訪問文件夾下載文件(.mp3)到客戶端電腦?從服務器文件夾下載文件到客戶端電腦
我曾嘗試:
let url = "\\public\\test.mp3";
let xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var a = document.createElement('a');
// xhr.response is a blob
a.href = window.URL.createObjectURL(xhr.response);
a.download = 'test.mp3';
a.style.display = 'none';
document.body.appendChild(a);
a.click();
};
xhr.open('GET', url);
xhr.send();
但這只是下載文件,15KB不是整個事情
你必須使用XHR來下載文件? –
也許你應該使用異步xhr ...同步方法已被棄用。 ['xhr.open('GET',url,true)'](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open)。另外,我非常懷疑這條道路是否有效。嘗試使用正斜槓從服務器獲取資源,如'/ public/test.mp3'所示。 –