I have a string value like 1,2,3
and i need convert to byte value like [1,2,3]
?
how to bind javascript byte to C# Byte[]
array
const file = e.files[0];
var reader = new FileReader();
reader.readAsArrayBuffer(file.rawFile);
reader.onload = function () {
var strBytes = new Uint8Array(reader.result).join();
var byte=???;
}
thanks
I have a string value like 1,2,3
and i need convert to byte value like [1,2,3]
?
how to bind javascript byte to C# Byte[]
array
const file = e.files[0];
var reader = new FileReader();
reader.readAsArrayBuffer(file.rawFile);
reader.onload = function () {
var strBytes = new Uint8Array(reader.result).join();
var byte=???;
}
thanks
Share Improve this question edited Jul 17, 2017 at 6:28 Koby Douek 16.7k20 gold badges78 silver badges110 bronze badges asked Jul 17, 2017 at 6:23 Hossein HaghHossein Hagh 1272 gold badges3 silver badges15 bronze badges 1-
2
.join()
converts theUint8Array
to a string. If you don’t want a string, don’t call.join()
. – Ry- ♦ Commented Jul 17, 2017 at 6:24
1 Answer
Reset to default 0When creating a Uint8Array
, the data is stored as bytes, which is exactly what you are looking for here.
What you've done when using .join()
is to create them as strings.
Just remove the .join
and you will have an array of bytes:
var strBytes = new Uint8Array(reader.result);