DEV Community

Ali Sina Yousofi
Ali Sina Yousofi

Posted on

1

Check if a user has enough internet speed for uploading a photo in JavaScript

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.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay