2

I am testing upload speed of my device! So i need some data to send to the server. Here i create some data.

var Send = new Blob([new ArrayBuffer(5e+8)], {type: 'application/octet-stream'});

Now i send it to the server

var xhr = new XMLHttpRequest;
xhr.open("POST", 'http://192.168.1.10/v4/upload', true);
xhr.send(Send)

The Problem is When i try to upload 90Mb or more data from Safari iPhone 6S. It is retuning an error

""Failed to load resource: WebKit encountered an internal error""

It depends on the size of the page etc. From an Empty page Safari on iPhone 6S Managed to send up to 100Mb of data. But i need large chunks of data like 500Mb or 1Gb.

Desktop Chrome/Safari/FF/IE on Mac/Windows allow more than 500Mb of data.

var Send = new Blob([new ArrayBuffer(5e+8)], {type: 'application/octet-stream'});
var xhr = new XMLHttpRequest;
xhr.open("POST", 'http://192.168.1.10/v4/upload', true);
xhr.send(Send);

How can i create large amount of data without using too-much memory. Also i need to Send it using XHR2. NO WSS etc.

Anyway we can do this?

  • Does this answer your question? [Failed to Load Resource, Plugin Handled Load on iOS](https://stackoverflow.com/questions/18103103/failed-to-load-resource-plugin-handled-load-on-ios) – Balaj Khan Feb 03 '20 at 07:01
  • @BalajKhan No! not a solution. – user3642342 Feb 03 '20 at 07:05
  • Send multiple smaller chunks? – JLe Feb 03 '20 at 07:18
  • Upload in CHUNKS is not a solution for this project. eg: for HighSpeed connection it will take only less than a second to send 500Mb of data. WE CANNOT ACCURATELY MASSEUR THE SPEED IF WE USE CHUNKS. @JLe – user3642342 Feb 03 '20 at 07:22

1 Answers1

0

Per specs you should be able to xhr.send() a ReadableStream, but AFAIK, no browser did implement that yet...

Otherwise that would have given something like

const stream = new ReadableStream({
  start(controller) {
    setInterval( () => {
      controller.enqueue( dummy_data );
    }, interval );
  }
});
const xhr = new XMLHttpRequest();
xhr.open('post', url);
xhr.send(stream);


A solution for your case would be to send a File from the device storage directly: create your file beforehand and select it with an <input type="file">, the browser should stream it for you.

fileInput.onchange = (evt) => {
  const xhr = new XMLHttpRequest();
  xhr.open('post', url);
  xhr.send(fileInput.files[0]);
};
Kaiido
  • 123,334
  • 13
  • 219
  • 285
  • Selecting file is not an optimal solution for testing speed. like this > http://openspeedtest.com/Get-widget.php – Vishnu Feb 03 '20 at 09:54
  • @Vishnu op is testing on intranet. They want to test their device. So for **their** case that may very well be viable. – Kaiido Feb 03 '20 at 10:02
  • Yes, " test their device" Upload speed, that means sending data to a server! Just like @Vishnu said selecting file is not an option here, also we don't know the space left on the device. We need to create an ARRAY and store 500Mb or more! and send it via XHR2. Can we use unTyped array and store Zero's worth of 500Mb and send it via XHR2? I try this but it is less efficient! VERY SLOW. – user3642342 Feb 03 '20 at 15:40
  • And why selecting a file is not an option? You still send it to the server (xhr.send(file)). That's the only way to do what you want anyway. But why do you even need 500MB. If you want to do the same as the service Visnu talked about, then 100MB is largely enough. – Kaiido Feb 03 '20 at 22:41
  • I am working for a project like http://openspeedtest.com/ where users will test office VPN, WAN etc. It will be High Speed connections. That means 100Mbps to 4Gbps. User may test from iPad, Mobile, PC, Server etc. It will be inconvenient and not practical to put a 500Mb file on a Samsung Smart Display. They use WebKit browser. 100Mb is good enough for speed up to 500Mbps when speed increase. To measure the line speed more accurately we need more data to send. Then only we get some time to measure the speed. That is why i am trying to send large amounts of data without using too-much memory. – user3642342 Feb 04 '20 at 02:09
  • And the only way from a web browser, and until browsers do implement the specs I highlighted in my answer, is by streaming a file from your user's filesystem (since you discarded web-sockets for I don't know what reasons. You could also make your own apps, but I'm not sure it's any more convenient than making them download a big file. – Kaiido Feb 04 '20 at 02:15