javascript找不到blob

问题描述 投票:0回答:2

因此,我知道blob仅在创建它们的选项卡中可用,但是不知何故,我收到一条错误消息,找不到该blob。在哪里尝试都无所谓。

例如,YouTube视频是blob,我可以通过它获取对象的URL

document.getElementsByTagName('video')[0].currentSrc /// => 'blob:http://youtube.com/asddasd-asdasd-asdasd-asddsa'

现在是否要尝试使用Blob

fetch(url)

我收到找不到该blob的错误。

javascript web html5-video blob fetch-api
2个回答
0
投票

我认为您应该先使用标准URL提取,然后指示应该将其解释为Blob。

const url = "http://youtube.com/asddasd-asdasd-asdasd-asddsa"
fetch(url)
  .then(response => response.blob())
  .then(console.log)

但是在获取youtube时您可能会遇到一些CORS问题!


0
投票

Youtube视频blobURI不是指向Blob,而是指向MediaSources

Blob不是我们可以使用URL.createObjectURL()方法指向的唯一对象,过去我们也能够传递MediaStreams,更重要的是,我们仍然可以传递MediaSource对象。

const source = new MediaSource();
const url = URL.createObjectURL( source ); // this doesn't throw
console.log( url ); // that's a valid blob URI

fetch( url ).catch( console.error ); // nothing to fetch there

YouTube确实以ArrayBuffers的形式获取数据,然后使用此数据填充MediaSource。

天生没有办法从blobURI中检索原始MediaSource,即使we can override URL.createObjectURL将其取回,我们仍然无法检索传递给MediaSource的实际数据...

© www.soinside.com 2019 - 2024. All rights reserved.