# Show image file size limit on user#preference page

**URL:** <https://meta.discourse.org/t/show-image-file-size-limit-on-user-preference-page/41707>\
**Category:** UX\
**Created:** [29. März 2016 um 11:34 UTC](https://meta.discourse.org/t/show-image-file-size-limit-on-user-preference-page/41707 "2016-03-29T11:34:10Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)\
**Post date:** [3. September 2016 um 02:22 UTC](https://meta.discourse.org/t/show-image-file-size-limit-on-user-preference-page/41707/17 "2016-09-03T02:22:02Z")

</div>

> [@tobiaseigen](#):
>
> Is there no way to have the client check the file size and complain if it is big, eg more than 1mb even, then give a warning before proceeding?

There is the HTML5 File API eg. from

> **[Using files from web applications - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/File_API/Using_files_from_web_applications)**
>
> Using the File API, web content can ask the user to select local files and then read the contents of those files. This selection can be done by either using an HTML element or by drag and drop.

```plaintext
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>File(s) size</title>
<script>
function updateSize() {
  var nBytes = 0,
      oFiles = document.getElementById("uploadInput").files,
      nFiles = oFiles.length;
  for (var nFileId = 0; nFileId < nFiles; nFileId++) {
    nBytes += oFiles[nFileId].size;
  }
  var sOutput = nBytes + " bytes";
  // optional code for multiples approximation
  for (var aMultiples = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"], nMultiple = 0, nApprox = nBytes / 1024; nApprox > 1; nApprox /= 1024, nMultiple++) {
    sOutput = nApprox.toFixed(3) + " " + aMultiples[nMultiple] + " (" + nBytes + " bytes)";
  }
  // end of optional code
  document.getElementById("fileNum").innerHTML = nFiles;
  document.getElementById("fileSize").innerHTML = sOutput;
}
</script>
</head>

<body onload="updateSize();">
<form name="uploadForm">
<p><input id="uploadInput" type="file" name="myFiles" onchange="updateSize();" multiple> selected files: <span id="fileNum">0</span>; total size: <span id="fileSize">0</span></p>
<p><input type="submit" value="Send file"></p>
</form>
</body>
</html>

```

Not the best support, but not all that bad either

> **[Can I use... Support tables for HTML5, CSS3, etc](https://caniuse.com#feat=fileapi)**
>
> "Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.

---

_[View the full topic](https://meta.discourse.org/t/show-image-file-size-limit-on-user-preference-page/41707)._
