影片標籤的 XMLHttpRequest?


HTML5 檔案 Blob.slice() 方法用於建立包含資料的 Blob 物件。此資料位於源 Blob 的指定位元組範圍內。它使用 XMLHttpRequest,如下例所示。

讓我們看一個使用 slice() 傳送和接收二進位制資料的示例。此示例傳送文字並使用 POST 方法將“檔案”傳送到伺服器

var val = new XMLHttpRequest();

val.open("POST", url, true);
val.onload = function (event) {
};
var blob = new Blob(['demo'], {type: 'text/plain'});
val.send(blob);

對於影片

req.onload = function () {
   var blob_uri = URL.createObjectURL(this.response);
   myElement.appendChild(document.createElement("source")).src = blob_uri;
};
req.responseType = "blob";

更新於: 2020 年 1 月 29 日

411 次瀏覽

開啟您的 事業

完成課程以獲得認證

開始
廣告
© . All rights reserved.