admin管理员组文章数量:1026900
function loadFileAsBinary()
{
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
var rs = textFromFileLoaded;
var charData = rs.split('').map(function(x){return x.charCodeAt(0);});
console.log(charData);
var bindata = new Uint8Array(charData);
console.log(bindata);
var plain = pako.inflate(bindata, {to: 'string' });
var strData = String.fromCharCode.apply(null, new Uint16Array(plain));
document.getElementById("inputTextToSave").value = strData;
};
fileReader.readAsBinaryString(fileToLoad);
}
I want to inflate upload file but this function gives an error:
Uncaught incorrect header check
function loadFileAsBinary()
{
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
var rs = textFromFileLoaded;
var charData = rs.split('').map(function(x){return x.charCodeAt(0);});
console.log(charData);
var bindata = new Uint8Array(charData);
console.log(bindata);
var plain = pako.inflate(bindata, {to: 'string' });
var strData = String.fromCharCode.apply(null, new Uint16Array(plain));
document.getElementById("inputTextToSave").value = strData;
};
fileReader.readAsBinaryString(fileToLoad);
}
I want to inflate upload file but this function gives an error:
Share Improve this question edited Jun 25, 2015 at 3:13 Pang 10.1k146 gold badges86 silver badges124 bronze badges asked Jun 25, 2015 at 2:44 이원우이원우 611 gold badge1 silver badge4 bronze badges 0Uncaught incorrect header check
1 Answer
Reset to default 1I was able to solve the same issue by using r.readAsArrayBuffer(f);
and
pako.inflate(new Uint8Array( e.target.result ) , {"to":"string"})
Here my code:
function changeInputFile(evt){
// Retrieve the first (and only!) File from the FileList object
var f = evt.target.files[0];
if (f) {
let r = new FileReader();
r.onload = function(e) {
var contents = e.target.result;
console.debug( "User layout file:\n"
+ "name: " + f.name + "\n"
+ "type: " + f.type + "\n"
+ "size: " + f.size + " bytes\n"
)
);
try {
let jsonContent = null;
if ( f.type == "application/gzip" ) {
jsonContent=pako.inflate(new Uint8Array( e.target.result ) , {"to":"string"});
} else {
// ...
}
// ...
} catch(e) {
console.error(e)
}
}
r.readAsArrayBuffer(f);
} else {
console.error("Failed to load file");
}
}
function loadFileAsBinary()
{
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
var rs = textFromFileLoaded;
var charData = rs.split('').map(function(x){return x.charCodeAt(0);});
console.log(charData);
var bindata = new Uint8Array(charData);
console.log(bindata);
var plain = pako.inflate(bindata, {to: 'string' });
var strData = String.fromCharCode.apply(null, new Uint16Array(plain));
document.getElementById("inputTextToSave").value = strData;
};
fileReader.readAsBinaryString(fileToLoad);
}
I want to inflate upload file but this function gives an error:
Uncaught incorrect header check
function loadFileAsBinary()
{
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
var rs = textFromFileLoaded;
var charData = rs.split('').map(function(x){return x.charCodeAt(0);});
console.log(charData);
var bindata = new Uint8Array(charData);
console.log(bindata);
var plain = pako.inflate(bindata, {to: 'string' });
var strData = String.fromCharCode.apply(null, new Uint16Array(plain));
document.getElementById("inputTextToSave").value = strData;
};
fileReader.readAsBinaryString(fileToLoad);
}
I want to inflate upload file but this function gives an error:
Share Improve this question edited Jun 25, 2015 at 3:13 Pang 10.1k146 gold badges86 silver badges124 bronze badges asked Jun 25, 2015 at 2:44 이원우이원우 611 gold badge1 silver badge4 bronze badges 0Uncaught incorrect header check
1 Answer
Reset to default 1I was able to solve the same issue by using r.readAsArrayBuffer(f);
and
pako.inflate(new Uint8Array( e.target.result ) , {"to":"string"})
Here my code:
function changeInputFile(evt){
// Retrieve the first (and only!) File from the FileList object
var f = evt.target.files[0];
if (f) {
let r = new FileReader();
r.onload = function(e) {
var contents = e.target.result;
console.debug( "User layout file:\n"
+ "name: " + f.name + "\n"
+ "type: " + f.type + "\n"
+ "size: " + f.size + " bytes\n"
)
);
try {
let jsonContent = null;
if ( f.type == "application/gzip" ) {
jsonContent=pako.inflate(new Uint8Array( e.target.result ) , {"to":"string"});
} else {
// ...
}
// ...
} catch(e) {
console.error(e)
}
}
r.readAsArrayBuffer(f);
} else {
console.error("Failed to load file");
}
}
本文标签: javascriptUncaught incorrect header check using pakojsStack Overflow
版权声明:本文标题:javascript - Uncaught incorrect header check using pako.js - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745652893a2161425.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论