URL.createObjectURL返回带空前缀的Blob.例如:Blob:null/12415-63 [英] URL.createObjectURL returns a blob with null prepended. Eg : Blob:null/12415-63

查看:758
本文介绍了URL.createObjectURL返回带空前缀的Blob.例如:Blob:null/12415-63的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

blob在开始处以null开头,例如:blob:null/72438-4637-23673-34721.但是,当我将src用作src时,它会显示正确的图像.

blob has null prepended at the start eg : blob:null/72438-4637-23673-34721. But when I use the same as a src to the , it shows up the correct image.

我正在使用URL.createObjectURL调用.我也尝试使用webkitURL.两者都返回在开头附加了null的blob. URL和webkitURL返回的Blob值也不相同.

I am using URL.createObjectURL call. I also tried using webkitURL. Both return a blob with null appended at the start. Also the blob value returned by URL and webkitURL are not the same.

这是代码段

        var dataUrl = canvas.toDataURL();

        // The last piece of the data URL after the comma
        var byteString = atob(dataUrl.split(',')[1]);

        // Populate an array buffer
        var arrayBuffer = new ArrayBuffer(byteString.length);
        var uint8Array = new Uint8Array(arrayBuffer);
        for (var i = 0; i < byteString.length; i++) {
            uint8Array[i] = byteString.charCodeAt(i);
        }

        var blob = new Blob([uint8Array], { type: "image/png" });
        var blobVal = URL.createObjectURL(blob);

这里的blobVal具有"blob:null/1234-5678-9012- ..."

Here the blobVal has "blob:null/1234-5678-9012- ..."

推荐答案

这就是来源,文件系统和沙盒iframe(可能是其他)的来源为null.如果您设置本地服务器,则应该说http%3A//localhost,即http://localhost网址编码

That's the origin, file system and sandboxed iframes(maybe others) have null as their origin. If you set up a local sever it should say http%3A//localhost, that's http://localhost url encoded

    var arrayBuffer = new ArrayBuffer(100);
	var uint8Array = new Uint8Array(arrayBuffer);
	for (var i = 0; i < 100; i++) {
		uint8Array[i] = i;
	}

	var blob = new Blob([uint8Array], { type: "image/png" });
	var blobVal = URL.createObjectURL(blob);
	$('div').html(blobVal);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>

这说http%3A//fiddle.jshell.net
http://jsfiddle.net/thsn3ayp/

这篇关于URL.createObjectURL返回带空前缀的Blob.例如:Blob:null/12415-63的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆