Commit 88ae8435 authored by limingzhe's avatar limingzhe

feat: xhr调试

parent ba5b918c
......@@ -14,8 +14,6 @@
</div>
<input type="file" value="请选择文件" />
<form method="POST" [action]="uploadUrl"></form>
<!-- <div style="position: absolute; top: 0">
<label style="font-family: Aileron-Black;"></label>
......
......@@ -745,7 +745,7 @@ export class PlayComponent implements OnInit, OnDestroy {
}
const startTime = new Date().getTime();
greadPapersForCheck({type: 'pos', blankWord: 'NN', word: 'apple'}, res => {
greadPapersForCheck({type: 'VB', blankWord: 'apple', word: 'apple'}, res => {
// res 需要toJSON
const endTime = new Date().getTime();
const durTime = endTime - startTime;
......@@ -799,15 +799,39 @@ export class PlayComponent implements OnInit, OnDestroy {
url2Blob (url) {
return new Promise(resolve => {
console.log(' in url2Blob ..')
console.log('url: ', url);
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = 'blob';
xhr.onload = () => {
if (xhr.status == 200) {
xhr.responseType = 'arraybuffer';
// xhr.onload = () => {
// console.log(' in url2Blob load end..')
// if (xhr.status == 200) {
// console.log(xhr.response);
// resolve(xhr.response);
// }
// };
xhr.onreadystatechange = () => {
if (xhr.readyState !== 4) {
return;
}
const status = xhr.status;
console.log ('status: ', status);
if ((status >= 200 && status < 300) || status === 304) {
console.log('request success');
console.log(xhr.response);
resolve(xhr.response);
} else {
console.log('request error');
console.log('xhr.response: ', xhr.response);
}
};
xhr.send();
......@@ -817,14 +841,16 @@ export class PlayComponent implements OnInit, OnDestroy {
uploadTestAudio(text, url, key) {
console.log(' in uploadTestAudio 111');
this.url2Blob(url).then((res) => {
console.log('res: ', res);
this.url2Blob(url).then((buffer) => {
console.log('res: ', buffer);
const startTime = new Date().getTime();
const blob = res //new Blob([u8arr], {type: mime});
const blob = new Blob([<ArrayBuffer>buffer], {type: "audio/mpeg"});
// const blob = res //new Blob([u8arr], {type: mime});
const fd = new FormData();
fd.append("file", <Blob>blob, 'test_audio.mp3');
this.http.post(this.uploadUrl, fd).subscribe((res) => {
......
......@@ -9,12 +9,12 @@
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script type="text/javascript" src="https://staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air_online_open.js"></script>
<!-- <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.9.0/vconsole.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.9.0/vconsole.min.js"></script>
<script>
// init vConsole
var vConsole = new VConsole();
console.log('Hello world');
</script> -->
</script>
</head>
<body>
<app-root></app-root>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment