프로그래밍 언어/Javascript
Javascript) 서버에서 보내는 Blob 객체 > File 객체 받기
seungyoon
2021. 11. 12. 09:46
var xhr = new XMLHttpRequest()
xhr.open("POST", "<파일 받을 서버 url>", true)
xhr.setRequestHeader('Content-type', 'application/json')
xhr.responseType = 'blob'
xhr.send(JSON.stringify(json)) // json을 바디에 담아서 요청 보낼 경우! 아니면 그냥 send()
xhr.onload = function() {
console.log(xhr)
var blob = xhr.response
var file = new File([blob], "sample") // blob 은 반드시 배열안에 담아야 한다!
console.log(file)
}
ajax로 받았더니 그냥 responseText에 바이너리로만 오길래 이 방법으로 했다. 담에 또 써먹어야지 히히