0

I'm working on a page that has streaming audio and many slides. The audio plays and the slides are loaded on demand during the event. Works fine during regular events but fails during large corporate events where the http download of a slide for 1000 users spikes the bandwidth and temporarily saturates the network causing the audio to skip / cut out.

I want to preload all the images upon the user opening the page but I was wondering if it is also possible to rate limit this download of all the images. I'd love to limit the preload of the images to a specific kb/s. Is this possible client side? If not what would be a good option server/client side?

deadcode
  • 25
  • 6
  • The good option is 'server-side'. see the question:http://stackoverflow.com/questions/5697605/limit-the-size-of-an-file-upload-html-input – Krupal Shah Jul 23 '14 at 17:24

1 Answers1

0

Client side validation for limiting file size is possible in JavaScript using the File APIs.

An excellent tutorial is here : Reading files in JavaScript using the File APIs.

One final point : You should not rely on 'only' client-side validation. You must use server-side validation.

UPDATE: (For 'only' client-side validation):

With the use of JS, you can try like this:

if (typeof FileReader !== "undefined") {
    var size = document.getElementById('myfile').files[0].size;
    // check file size
}

(This may not be supported by all browsers.Only latest versions of Webkit browsers will support this.)

OR with the FILE API, you can try like this:

<input type="file" id="fileInput" />
var size = document.getElementById("fileInput").files[0].size;
Krupal Shah
  • 8,949
  • 11
  • 57
  • 93
  • Can this be used to read from a URL? Not just a local file / blob? – deadcode Jul 23 '14 at 17:41
  • can you tell me which server side language you are using? – Krupal Shah Jul 23 '14 at 17:45
  • c#; but the files are hosted on a CDN and requested from the CDN directly from javascript. – deadcode Jul 23 '14 at 17:48
  • @deadcode I have updated the answer...please see that. – Krupal Shah Jul 23 '14 at 18:00
  • @deadcode Also one point I want to say that this is not a complete answer...All I can do is to hint you about the ways in which you can do this...This is because of the fact that the answer will have to be described in very broad manner..I assume you understand it...You should have to search for more about the things within the answer. – Krupal Shah Jul 23 '14 at 18:06
  • I think the one disconnect is that you are placing the file into an input presumably for upload. This is not the use-case. We already have the files for the slides stored at the CDN. It is merely a problem of getting them to the browser in a rate-limited fashion so that the HTTP spikes of 1000s of users doing a GET on an image doesn't overload the network. Uploading and file inputs are no where relevant in the use-case. – deadcode Jul 23 '14 at 18:40