简体   繁体   中英

Download file from server folder to client pc

How can you download a file (.mp3) from a publicly accessible folder on the server to the clients pc?

I have tried:

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();

But this just downloads the file with 15KB not the entire thing

只需将用户导航到mp3文件:

window.location.href = '\\\\public\\\\test.mp3';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM