I am trying to convert image to byte array using only javascript and send to api. I have found this answer but it only shows to convert to base64 then send it to server side. Are there any other ways to convert to byte array using js or I can't just send byte array to api ?
Related
I am trying to transfer AES key generate in js:
var AESkey = forge.random.getBytesSync(16);
exapmle if printed condsole i have "§½üå8bdÈP"
but printed in my java server it is "—§‡½Â\u001eĂĽĂĄ8b\u000edĂ?\u0012P›"
(other data are ok)
I tried to get the bytes with Buffer.from(AESkey) but instead of getting a 16 bytes buffer I get a 22/24/25.. buffer lenghts.
In which format can I transfer the key and how can I get my AESkey to that format in js?
A possible solution:
make a base64 encoded string on client side
send base64-encoded string to server
decode base64 in Java to get the byte sequence back
This way the byte sequence can be safely transported.
I have an ArrayBuffer in angularjs that I am trying to send to my backend endpoint in c#, I thought it was a regular byte array but it's not mapping appropriately
What would an ArrayBuffer map to as an object in c# if not a byte[]?.
I have a PDF file represented as that ArrayBuffer but now I would like to send it to the server, or perhaps is there a way to convert that ArrayBuffer to a File type in JavaScript and send it o the endpoint so that I can use something like an IFormFile?.
Thank you
I had a situation of same some long days back. What I did was, I converted the array buffer data to base 64 string in the js side and sent it to the backend c# code using post method,and again I decoded it to array buffer to regenerate the file on server side. By this way I achieved the mapping.
I used this code which helps to convert the array buffer to base 64 string in JS.
and this api of .net framework to convert back the base 64 string to file buffer.
I hope this would help you.
I'm storing several mp3 files in MS SQL Server'08 as BLOB objects (I use filestream). There's a WCF service which can send one of this objects to html client.
Preliminarily I convert BLOB to byte[] using ToArray().
How to convert incoming byte[] array to audio(mp3) and play it?This's only javascript/html on client.
I use SoundManager2 http://www.schillmania.com/projects/soundmanager2/
to play audio.
Thanks!
I want to send data from Javascript to a WebSocket server and also from a WebSocket server to Javascript.
I want to send this:
Headers
-------
Field 1: 2 byte hex
Field 2: 2 byte hex
Field 3: 4 byte hex
Data
----
Field1 : 2 byte hex
Field1 : 8 byte hex
From Javascript, I can send a two-byte value via
socket = new WebSocket(host);
...
socket.send(0xEF);
But I want to send multiple fields, together...let's say 0xEF, 0x60, and 0x0042.
How do I do this?
And, how to I interpret via Javascript data containing multiple fields coming from the WebSocket server?
You can send data as a string. For example:
socket.send("hello world");
I recommend you to use JSON as data format. You can convert JSON strings directly into objects and vice versa. It's so simple and useful!
You can send data as JSON objects.
socket.send(JSON.stringify({field1:'0xEF', field2:'0x60',field3: '0x0042'}));
Sound like what you are asking is how to send binary data over a WebSocket connection.
This is largely answered here:
Send and receive binary data over web sockets in Javascript?
A bit of extra info not covered in that answer:
The current WebSocket protocol and API only permits strings to be sent (or anything that can be coerced/type-cast to a string) and received messages are strings. The next iteration of the protocol (HyBi-07) supports binary data is currently being implemented in browsers.
Javascript strings are UTF-16 which is 2 bytes for every character internally. The current WebSockets payload is limited to UTF-8. In UTF-8 character values below 128 take 1 byte to encode. Values 128 and above take 2 or more bytes to encode. When you send a Javascript string, it gets converted from UTF-16 to UTF-8. To send and receive binary data (until the protocol and API natively support it), you need to encode your data into something compatible with UTF-8. For example, base64. This is covered in more detail in the answer linked above.
I use to render data using EntityDataSource, and I use to store customer image as byte in database, the problem is how can I convert that byte to base64 on .aspx page itself to use it as image src, is there any way to do this in javascript.
Why do you need to convert a byte[] to base64 string? This won't allow you showing the image on the page. You could write a generic handler (.ashx) that will query the database, fetch the image bytes and write them to the response stream. Then you simply instruct your image src property to this generic handler.