从JavaScript二进制字符串斑点 [英] Blob from javascript binary string
问题描述
我有创建一个二进制字符串FileReader.readAsBinaryString(BLOB)。
我要创建这个二进制字符串psented二进制数据重新$ P $的Blob。
是你使用的不可用了团块?结果
你必须使用 readAsBinaryString
?您可以使用 readAsArrayBuffer
来代替。对于数组缓冲区它会更容易重新团块。
如果不是你可以建立回他通过字符串循环,建设一个字节数组,然后从它创建一个blob的Blob。
$('输入')。改变(函数(){\r
VAR FRB =新的FileReader();\r
frb.onload =功能(){\r
变种I,L,D,数组;\r
D = this.result;\r
L = d.length;\r
阵列=新Uint8Array(升);\r
对于(VAR I = 0; I<升;我++){\r
数组[我] = d.char $ C $猫(I)\r
}\r
变种B =新的Blob([数组] {类型:应用程序/八位字节流'});\r
window.location.href = URL.createObjectURL(B);\r
};\r
frb.readAsBinaryString(this.files [0]);\r
\r
\r
});
\r
&LT;脚本SRC =https://ajax.googleapis.com/ajax /libs/jquery/1.9.1/jquery.min.js\"></script>\r
&LT;输入类型=文件&GT;
\r
I have a binary string created with FileReader.readAsBinaryString(blob).
I want to create a Blob with the binary data represented in this binary string.
Is the blob that you used not available for use anymore?
Do you have to use readAsBinaryString
? Can you use readAsArrayBuffer
instead. With an array buffer it would be much easier to recreate the blob.
If not you could build back he blob by cycling through the string and building a byte array then creating a blob from it.
$('input').change(function(){
var frb = new FileReader();
frb.onload = function(){
var i, l, d, array;
d = this.result;
l = d.length;
array = new Uint8Array(l);
for (var i = 0; i < l; i++){
array[i] = d.charCodeAt(i);
}
var b = new Blob([array], {type: 'application/octet-stream'});
window.location.href = URL.createObjectURL(b);
};
frb.readAsBinaryString(this.files[0]);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type="file">
这篇关于从JavaScript二进制字符串斑点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!