bricks/bricks/binstreaming.js
2024-08-04 14:38:35 +08:00

35 lines
600 B
JavaScript

bricks = window.bricks || {};
bricks.UpStreaming = class extends bricks.JsWidget {
/*
{
"url":
}
*/
constructor(opts){
super(opts);
}
async go(){
this.body = new ReadableStream(this);
this.headers = new Headers();
this.headers.append('Content-Type',
'application/octet-stream');
var resp = await fetch(this.url, {
method: 'POST',
headers: this.headers,
duplex: 'full',
body: this.body
});
return resp
}
send(data){
this.stream_ctlr.enqueue(data);
}
finish(){
this.stream_ctlr.close();
}
start(controller){
this.stream_ctlr = controller;
}
}