0

I have a blob of size (300MB) approx and have converted it to byte array (as its customer requirement) and now I am trying to post this byte array to server through AJAX as shown below:

$.ajax({
    url: "http://p80ee.mocklab.io",
    type: 'POST',
    contentType: 'application/json',  
    data: ui8,
    success: function (result) {
        console.log("Response : " , result);
    }
 });

but server is showing error because of long data as shown below Error Message

Can I post this byte array in stream form? if yes, then how ?

Someone please help if know the answer

Ali Raza
  • 113
  • 8
  • 1
    Use the Fetch API with ReadableStream API. Browser restrictions apply. – Randy Casburn Oct 17 '18 at 13:37
  • @RandyCasburn Thanks for reply, but I need to post data without any get request from the server and as I searched, both Fetch API and ReadableStream APIs works on get Request – Ali Raza Oct 17 '18 at 14:08
  • As I said, with browser restrictions, open this in Chrome and check the network tab of the dev tools - watch the readable stream POST happen: https://jsbin.com/nepinen/1/edit?js,console Please see: https://stackoverflow.com/questions/40939857/fetch-with-readablestream-as-request-body – Randy Casburn Oct 17 '18 at 14:32
  • What do you call a "byte Array"? Most of the time when an end-point asks you to send a "Byte Array" that just means send the data a multipart-encoded (i.e what was a Blob or an ArrayBuffer for js). So that would just be `fetch(uri, {method:'POST', body: your_blob})` and don't mind converting anything anywhere. – Kaiido Oct 18 '18 at 08:57
  • byte Array in JS means an array of this type `var a = [22, 152, 65]` etc where these numbers are the ASCII values of characters. I have a blob but its size is large and it is not working in just one post request – Ali Raza Oct 18 '18 at 10:57
  • 1
    @AliRaza no a byte array in js means nothing. And I never saw any endpoint expecting a JSON string representing an array of codepoints.. And there is no limitations to the size of binary data you can POST through fetch, only server side will have. – Kaiido Oct 19 '18 at 04:40
  • @Kaiido, I checked many examples and byte array in JS is same as Unit8Array and its customer requirement to send this type of post request where ui8 is as `ui8 = JSON.stringify({array: 'video byte array'})` Also yes, its the limitation at server side but we have to post complete data to it. Thats why I am asking whether it is possible through streaming in AJAX or not and if its yes then how ? – Ali Raza Oct 19 '18 at 07:35

0 Answers0