0
어떻게 파일 (.mp3)을 서버의 공개적으로 액세스 할 수있는 폴더에서 클라이언트 PC로 다운로드 할 수 있습니까?서버 폴더에서 클라이언트 PC로 파일 다운로드
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();
그러나 이것은 단지
당신을합니까를 XHR을 사용하여 파일을 다운로드해야합니까? –
아마도 비동기 xhr ...을 사용해야합니다. 동기 메서드는 더 이상 사용되지 않습니다. ['xhr.open ('GET', url, true)'] (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open). 또한, 나는 그 경로가 유효하다는 것을 매우 의심합니다. '/ public/test.mp3'와 같이 서버에서 리소스를 가져 오기 위해 슬래시를 사용하십시오. –