【发布时间】:2016-12-07 10:10:20
【问题描述】:
我在尝试从不同域下载视频时遇到了 CORS 错误。我尝试了很多来解决它,但无法解决。 下面是我的js代码。
getVideoFile = function () {
var xhr = new XMLHttpRequest(),
blob;
xhr.open("GET",myVideo, true);
xhr.responseType = "blob";
xhr.addEventListener("load", function () {
if (xhr.status === 200) {
blob = xhr.response;
putVideoInDb(blob);
window.alert("Video file downloaded");
}
else {
window.alert("Unable to download video");
}
}, false);
xhr.send();
};
putVideoInDb = function (blob) {
var transaction = db.transaction(["Videos"], "readwrite");
var store = transaction.objectStore("Videos");
var vid = {
videoName:videoName,
video:blob,
}
var request = store.add(vid);
request.onerror = function(e) {
console.log("Error",e.target.error.name);
}
request.onsuccess = function(e) {
console.log("Done!!");
}
};
【问题讨论】:
标签: javascript indexeddb