简体   繁体   English

在javascript ArrayBuffer中访问Uint8Array

[英]Access Uint8Array in javascript ArrayBuffer

I've got a javascript ArrayBuffer generated from a FileReader ReadAsArrayBuffer method on a jpeg file. 我从jpeg文件的FileReader ReadAsArrayBuffer方法生成了一个javascript ArrayBuffer。

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). 我正在尝试访问ArrayBuffer的UInt32数组并将其发送到WCF服务(最终将其插入服务器上的数据库中)。

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. 我在这里看到了一个关于stackoverflow( 字节数组方法 )的示例,其中UnInt32数组被转换为我认为可以工作的字节数组。

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. 我正在尝试访问下面的arrayBuffer变量的[[Uint8Array]],以便可以将其发送到WCF,但是运气不佳。 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. 关于如何访问该[[Uint8Array]]的任何想法将不胜感激。 When the entire ArrayBuffer is sent to WCF Service I get a 0 byte array -- cant read it 当整个ArrayBuffer发送到WCF服务时,我得到一个0字节的数组-无法读取

Thanks 谢谢

Pete 皮特

在此处输入图片说明

Those properties do not actually exist on the ArrayBuffer object . 这些属性实际上不存在于ArrayBuffer对象上 They are put there by the Dev Tools window for viewing the ArrayBuffer contents. 它们被放置在“开发工具”窗口中,以查看ArrayBuffer的内容。

You need to actually create the TypedArray of your choice through its constructor syntax 您需要通过其构造函数语法实际创建您选择的TypedArray

 new TypedArray(buffer [, byteOffset [, length]]); 

So in your case if you want Uint8Array you would need to do: 因此,如果您要使用Uint8Array ,则需要执行以下操作:

var uint8View = new Uint8Array(arrayBuffer);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM