Show image file size limit on user#preference page

The problem is when I am trying to upload large image, there is no information regarding the file size limit of uploaded image. Please take a look at following screenshot

In my country the internet connection is very bad, the upload speed is very slow, so if I’m trying to upload 10MB image, it could take 2-3 minutes to complete, then Discourse give me the error alert when the uploading is finished :frowning:

I’ve checked the code that Discourse optimize the uploaded image until reach SiteSetting.max_image_size_kb value, otherwise it can’t save the image

Any idea how this could be solved?
Actually I would like to send pull request to add more message on each instructions, but I’m not convince that it will be accepted

4 Likes

We don’t test for file size on the client-side since we now automagically try to downsize large images.

Sure, I support adding the maximum image size in the instructions.

3 Likes

OK so the root issue is that we can’t tell you that your file was rejected until after it is uploaded.

But: if you are operating from a place with terrible bandwidth, why would you upload a very large image to start with? That doesn’t make sense to me.

I appreciate the contribution, but I feel this is not the correct solution, and it adds a fair bit of code and new translations, and does not address the root problem at all: you don’t know that your upload was rejected until after you upload it.

The types of users that will get this wrong, are unlikely to click a “read more” in my opinion.

I have planned to add information in simple text format, but I want to make
it reusable in other functions, so that’s why the UI is like clickable
format and add more code

I’m thinking another solution for this problem

Wait, is there any reason a simple

(max: 10MB)

wouldn’t do?

2 Likes

It wouldn’t but it still feels like trivia for the sake of trivia. Do Twitter or Facebook print a max next to their image upload controls for profiles? I doubt it.

Checked via desktop sites…
No, they don’t - simply selecting “upload” shows a file dialog.
They don’t show any size indicator for profile pictures nor images, simply an upload link / button.

3 Likes

Maybe because they don’t give limitation to the file size of uploaded image

Are you sure? Did you try uploading a 20mb image there?

I just uploaded an image with size 26,588,644 bytes (26.6 MB on disk) and succeed.
I also just found this page, facebook says that the limit is 25MB.

3 Likes

Can you try again with an image which is at least 30MB? Depending on the filesystem, the size of the file can vary slightly and a 26MB image might actually only require a bit less than 25MB on another filesystem :wink:

(They might be automatically downsizing images too)

I just uploaded an image from this page, I picked world.topo.bathy.200406.3x21600x21600.C1.jpg image, they say that is 36 MB, but on my laptop the size is 88,661,060 bytes (88.7 MB on disk), however the result is succeed, it’s on my fb

4 Likes

So they don’t actually enforce a limit. Interesting :thinking:

Thanks for doing the work.

4 Likes

It makes sense mentioning the file size limit . A forum is not like facebook , twitter in many way

yes agreeed
but sometimes Discourse’s image compressor able to compress the image file
into significant smaller size
e.g.: the file size limit is 10MB, and an user uploaded 15 MB image, then
validation status will depend on image compressor, is it succeeds or not to
compress the image until under 10MB

This issue is very real in my community. What is odd is that people in low bandwidth countries often try to upload a big file to discourse, it fails, then they email it to me using Gmail and ask me to post it for them. I then resize it myself before uploading and it works. Go figure.

So maybe Gmail has a more failsafe upload system for large files?

Is there no way to have the client check the file size and complain if it is big, eg more than 1mb, then give a warning before proceeding?

There is the HTML5 File API eg. from

<!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

1 Like

Hi @tobiaseigen, @Mittineague
Please take a look at Jeff comments on my pull request at github regarding this issue

2 Likes

this is back again on my site. people really struggle with this why not indicate a file size limit on the picture upload page? Or (better) sort of better error handling when a picture upgrade fails?

Here’s what people commonly see on my site. See screenshot sent to me by a member of my site.

1 Like

@zogstrip we probably want some sort of error here if people upload a gigantic avatar, can you confirm it is in place?

2 Likes