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 ?
-
If you are just wanting to convert a file that you've uploaded into a byte array, you might be able to use the solution to this question: stackoverflow.com/questions/37134433/…Sxribe– Sxribe2020-12-28 04:09:57 +00:00Commented Dec 28, 2020 at 4:09
-
This all depends on how you're getting your input. Most of the time, you want a Uint8Array or ArrayBuffer to efficiently send your data to the API, but to get that you will need either FileReader.readAsArrayBuffer (if from a user upload) or CanvasRenderingContext2D.getImageData().data. See developer.mozilla.org/en-US/docs/Web/API/FileReader/… and developer.mozilla.org/en-US/docs/Web/API/….101arrowz– 101arrowz2020-12-28 04:14:17 +00:00Commented Dec 28, 2020 at 4:14
Add a comment
|