Published on

Checking if user has enough internet speed to upload a photo

Authors
  • avatar
    Name
    Ali Sina Yousofi
    Twitter

Check if a user has enough internet speed for uploading a photo in JavaScript (chrome browser)

For chrome browser

We can use the navigator.connection API to get the estimated data transfer rate and compare it with the size of the photo that the user wants to upload.

Here is an example code snippet that checks if the user has enough internet speed to upload a photo of a certain size:

Image description

In this example, we assume that the minimum required upload speed is 2 Mbps, and the photo size to upload is 5 MB (5000000 bytes). We calculate the maximum upload time in seconds based on the photo size and minimum required speed, and then calculate the maximum allowed photo size based on the estimated speed and maximum upload time. If the photo size to upload is less than or equal to the maximum allowed size, we consider that the user has enough internet speed to upload the photo. Otherwise, we consider that the user does not have enough internet speed.

Thanks for reading 🙏🏻