Html 从“blob”网址检索下载文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37962620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
retrieve a download a file from a "blob" url
提问by giovaZ
A website have a video tag element structured like this:
一个网站有一个视频标签元素,结构如下:
<video id="playerVideo" width="450px" autoplay="autoplay" height="338px" style="height:100%;width:100%;" class="mejs-rai-e" src="blob:http%3A//www.example.com/d70a74e1-0324-4b9f-bad4-84e3036ad354"></video>
As you can see the src element have an url pre-configured as blob. Is there a method like a script or a video downloader plug-in to locate the file and download it?
如您所见,src 元素有一个预先配置为 blob 的 url。有没有像脚本或视频下载插件这样的方法来定位文件并下载它?
回答by chippie3000
If you have the blob url, you can set the hrefattribute from an <a>
(link) tag to download the file.
如果您有 blob url,则可以从(link) 标记设置href属性<a>
以下载文件。
In the following example I created the blob url using the xhr response. The answer to the question basically you can find in the function called download().
在以下示例中,我使用 xhr 响应创建了 blob url。这个问题的答案基本上可以在名为download()的函数中找到。
function setVideo(blob)
{
var url = URL.createObjectURL(blob);
var video = document.getElementById('playerVideo');
video.type = "video/mp4";
video.src = url;
video.load();
download(url);
}
function download(blob_url)
{
var fileName = "video.mp4";
var a = document.createElement('a');
a.href = blob_url;
a.download = fileName;
a.textContent = "DOWNLOAD " + fileName;
document.getElementById('blobURL').innerHTML = "BLOB URL: <b>"+blob_url+"</b>";
document.getElementById('download').appendChild(a);
}
$(document).ready(function(){
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
setVideo(xhr.response);
};
xhr.open('GET', 'https://cors-anywhere.herokuapp.com/http://techslides.com/demos/sample-videos/small.mp4');
xhr.send();
});
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<h1>My Page</h1>
<p>Some paragraph.</p>
<video id="playerVideo" width="320" height="240" autoplay="autoplay" muted>
Your browser does not support the video tag.
</video><br>
<span id="blobURL"></span><br>
<span id="download"></span>
</body>
</html>
回答by SidD
I was also looking for the same, but after so many days of search i could not find one(chrome extension),as the last option i downloaded GETFLV software,it plays the video in the application itself and you are able to download the video.Alternatively you can also use KeepVid Pro.
我也在寻找相同的,但经过这么多天的搜索,我找不到一个(chrome 扩展),作为最后一个选项,我下载了 GETFLV 软件,它在应用程序本身中播放视频,您可以下载视频.或者,您也可以使用 KeepVid Pro。
回答by Riccardo Volpe
I used jDownloader to download a video like in your question; it's a free multiplatform program written in Java, as the "j" before its name suggests. You simply need to copy the url of the page that has the video, and the program will scan the webpage to find all that can be downloaded. Very useful, try it (http://jdownloader.org/download/index).
我使用 jDownloader 下载了您问题中的视频;它是一个用 Java 编写的免费多平台程序,正如其名称前的“j”所暗示的那样。您只需要复制包含视频的页面的 url,程序就会扫描网页以找到所有可以下载的内容。非常有用,试试吧(http://jdownloader.org/download/index)。