Array length is getting changed after putting that in KV store

Code :

await request.arrayBuffer().then((buffer) => {

img = new Int32Array(buffer);
console.log('image length');
console.log(img.length);

});
let value = await MY_KV.get(“my_array3”);
if(value === null){
await MY_KV.put(“my_array3”, img);
value = await MY_KV.get(“my_array3”);
console.log(‘value length’);
console.log(value.length);
}

Console :

image length

480000

value length

1920000

This will get it as a string, you will instead want it to read as an ArrayBuffer

You can do that with the type option (KV · Cloudflare Workers docs)

value = await MY_KV.get(“my_array3”, { type: 'arrayBuffer' });