Storing Uint8Array data to IPFS changes data when getting the same data #1282
Description
- Version: 0.27.7
- Platform: Linux
- Subsystem: Archlinux Zen Kernel
Type:
Problem
Severity:
High
Description:
I am trying to store an image to IPFS from my nodejs Server, The image is represented with an Uint8Array sent from my angular5 Client so basically :
WebClient (angular5) => NodeJs(Express) => IPFS node
When sending data form my web client i can see that i am sending an Uint8Array of 4000 items
Uint8Array[4000]
. When getting it back from IPFS and then sending it to my Web client i find out an Uint8Array of more than 4000 mostly double the number of items ( something like Uint8Array[8000]
) and it doesn't translate to an image when reading it afterwards ( using FileReader)
This is my code :
This is the image reading function
const reader = new FileReader();
reader.onload = (e) => {
let file=reader.result;
let buff = new Buffer(file);
that.CustomerInfo["KImage"] = buff;
console.log("read the file into buffer", that.CustomerInfo)
that.ConfirmButtonDisabled=false;
}
reader.readAsBinaryString(NativeInput.prop('files')[0]);
With NativeInput the Jquery input item.
this is the storing function from my nodeJs Server :
return new Promise(function (resolve, reject) {
try{
Localipfs.files.add(url, function(err, result) {
if (err) {
reject("Content submission error:", err);
console.error("Content submission error:", err);
} else if (result && result[0] && result[0].hash) {
console.log("Content successfully stored. IPFS address:", result[0].hash);
resolve(result[0].hash);
} else {
reject("Unresolved content submission error");
console.log(result);
console.error("Unresolved content submission error");
}
});
}catch (e){
console.error("error from storing content"+e);
}
})
}
the url argument is a nodeJs Buffer from the Uint8Array sent from my webClient.
this is the data getting function from IPFS
function getContent(hash){
return new Promise((res,rej)=>{
LIPFS.object.data(hash).then(
data=>{
console.log(JSON.stringify(data));
res(data);
}
).catch(
err=>{
rej(err);
}
)
})
}
When logging the stringifyed data, i get a json object with type: Buffer and a data field which is an array of Uint8 but it turns out that is not the data i stored.
I searched elsewhere and i am not sure between a bug/problem with my IPFS or a problem of conversion between NodeJs Buffers and Web Buffers.