2024-08-04 14:31:48 +08:00
|
|
|
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,
|
2024-08-04 14:38:35 +08:00
|
|
|
duplex: 'full',
|
2024-08-04 14:31:48 +08:00
|
|
|
body: this.body
|
|
|
|
});
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
send(data){
|
|
|
|
this.stream_ctlr.enqueue(data);
|
|
|
|
}
|
|
|
|
finish(){
|
|
|
|
this.stream_ctlr.close();
|
|
|
|
}
|
|
|
|
start(controller){
|
|
|
|
this.stream_ctlr = controller;
|
|
|
|
}
|
|
|
|
}
|