Created
March 18, 2018 07:38
-
-
Save chen0040/2bacc0bf16a551940eaae7df8d3828c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getBinaryObjById(id: number, token: string) { | |
const req = { | |
token: string | |
}; | |
Observable.create(observer => { | |
let xhr = new XMLHttpRequest(); | |
xhr.open('POST', './erp/binary-obj/find-binary-obj-by-id?id=' + id, true); | |
xhr.setRequestHeader('Content-type', 'application/json'); | |
xhr.responseType='blob'; | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState === 4) { | |
if (xhr.status === 200) { | |
var contentType = "application/octet-stream"; | |
var blob = new Blob([xhr.response], { type: contentType }); | |
console.log(blob); | |
observer.next(blob); | |
observer.complete(); | |
} else { | |
observer.error(xhr.response); | |
} | |
} | |
}; | |
xhr.send(JSON.stringify(req)); | |
}).subscribe(blob => { | |
console.log(blob); | |
let reader = new FileReader(); | |
reader.onloadend = function () { | |
window.location.href = reader.result; | |
}; | |
reader.readAsDataURL(blob); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment