I'm building a Chrome extension in which I simulate form POST to send images over to a server. I managed to upload the file, yet its content is distorted. By comparing the byte array of the uploaded and the original, it can be observed that every byte > 127 is transformed into 2 other bytes.
E.g: 137 -> 194 137
233 -> 195 169
The POST payload in Chrome developer tool suggests that the redundant byte is added before the request is sent.
My original file Content:
‰PNG ....
And content recorded in web payload
‰PNG ....
A char not supposed to be there precedes the content. Do you have any idea how to avoid this issue? Below is the code I use to test:
var fr = new FileReader();
fr.onloadend = function(evt){
if(evt.target.readyState == FileReader.DONE){
//str - image content
var str = "";
var byteStr = "";
var dv = new DataView(evt.target.result);
console.log("data length = " + evt.target.result.byteLength);
for(var i = 0 ; i < evt.target.result.byteLength; i++){
var b1 = dv.getUint8(i);
str += String.fromCharCode(b1);
byteStr += b1 + " ";
}
console.log(str);
console.log(byteStr);
//use jQuery.ajax to post image to server
attachImage(str, file.name,file.type);
}
}
fr.readAsArrayBuffer(file);
Thank you in advance.