I've got a javascript ArrayBuffer generated from a FileReader ReadAsArrayBuffer method on a jpeg file.
I'm trying to access the UInt32 array of the ArrayBuffer and send to a WCF service (ultimately to be inserted into a database on the server).
I've seen an example here on stackoverflow (byte array method) where a UnInt32 array is converted to a byte array which I think would work.
I'm trying to access the [[Uint8Array]] of my arrayBuffer variable below so I can send it to the WCF, but I'm not having much luck. I've tried:
var arrayBuffer = reader.result[[Uint8Array]];//nope
var arrayBuffer = reader.result[Uint8Array];//nope
var arrayBuffer = reader.result.Uint8Array;//nope
var arrayBuffer = reader.result[1];//nope
Any ideas on how to access that [[Uint8Array]] would be appreciated. When the entire ArrayBuffer is sent to WCF Service I get a 0 byte array -- cant read it
Thanks
Pete
For instance: Uint8Array – treats each byte in ArrayBuffer as a separate number, with possible values from 0 to 255 (a byte is 8-bit, so it can hold only that much). Such value is called a “8-bit unsigned integer”. Uint16Array – treats every 2 bytes as an integer, with possible values from 0 to 65535.
The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. It is an array of bytes, often referred to in other languages as a "byte array".
1. A Buffer is just a view for looking into an ArrayBuffer . A Buffer , in fact, is a FastBuffer , which extends (inherits from) Uint8Array , which is an octet-unit view (“partial accessor”) of the actual memory, an ArrayBuffer .
You can use the set method. Create a new typed array with all the sizes. Example: var arrayOne = new Uint8Array([2,4,8]); var arrayTwo = new Uint8Array([16,32,64]); var mergedArray = new Uint8Array(arrayOne.
Those properties do not actually exist on the ArrayBuffer object. They are put there by the Dev Tools window for viewing the ArrayBuffer contents.
You need to actually create the TypedArray of your choice through its constructor syntax
new TypedArray(buffer [, byteOffset [, length]]);
So in your case if you want Uint8Array
you would need to do:
var uint8View = new Uint8Array(arrayBuffer);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With