Image upload max size and further resizing regression issue


(Anton) #1

Continuing the discussion from Resize images after uploading:

Not sure if this has been discussed already and whether it has been considered a bug or an expected behavior.

The issue is, my setup won’t accept images up to 10MB. It will only accept images up to the size configured in the max_image_size_kb setting.

So if I set it as small as 860KB, that becomes the maximum size accepted while uploading the image.

What I expect instead is that images up to 10MB are accepted, and then resized to the maximum size configured in the setting.


(Jeff Atwood) #2

That is not the meaning of the setting.

Hmm let’s clarify with @zogstrip first.


(Régis Hanol) #3

Well, if you upload a 8MB image, there might be a chance we won’t be able to automatically resize it down to 860KB in the limited amount of time we allow for size reduction.

We limit this process since it is very CPU intensive and can be used as a DDoS vector.

What’s more, there is no way to predict the size of an image before actually resizing it.
This is what makes this hard…


(Anton) #4

Sure, all the reasoning makes a lot of sense.

But the error message is confusing and does not explain what is going on.

I’m trying to upload an image which is much less than 10MB, and the error message says “sorry the max you can upload is 860KB”. Makes no sense for end users.

If it can’t be resized in time, an error message should say something like that and help the user to understand what to do next.

The only thing they can try after reading the existing message is to downsize the image to 860kb, why they actually don’t need to.

Makes sense?

So, I suppose there is an issue, it is either of the two:

  1. Which error messages are used in which scenarios
  2. Uploading limitation issue?

(Jeff Atwood) #5

Are you uploading a very large png? If so do not do that; switch to jpg.


(Anton) #6

Sometimes it’s just an image from clipboard that I insert directly via Ctrl+V.

Despite I can educate myself to save images in JPG and then upload them, there is still that issue of an error message that confuses and makes little sense.

If it is said that an images up to 10MB can be uploaded (and we say that to our users as well), why can’t they upload an image of e.g. 2MB or 3MB or 4MB? It is less than 50% of the allowed size, yet that error pops up that says “sorry up to 864KB” only. It is this error messaging that I’m trying to get fixed.

I mean, it seems as if the error message does not reflect the actual issue and does not help user solve the issue but to dramatically sizedown their images.

If it was unable to size the image down, it should say something about it — i.e. your image is fine in size but we couldn’t resize it, try resizing it to half of its size before uploading etc - something like that.

Btw:

  • can we make this time limit configurable?
  • can we queue image resizing which failed and display the image thumbnail in the meantime? (the server might be idle at night)
  • just as an idea, using image number limit per TL can eliminate DDoS vector.

(Régis Hanol) #7

I agree we can do better on that front.

It isn’t possible right now but isn’t hard to do.

I’ll think about it.


EDIT:

  • client-side: we could add a warning when the image size is larger than the maximum allowed (letting the user know that the final image will be downsized)
  • server-side: use the thumbnail in the post but run a background job that will try (harder) to downsize the original image

@team what do you think?


(Jeff Atwood) #8

I don’t really see what the problem is – if the image is large, always try JPG first.

PNG on large images is incredibly risky. Just start with JPG on large dimension images and if you get good results, don’t go any farther.


(Anton) #9

Here is how I see it — the problems are:

  1. The error messages are misleading and can be improved to make more sense
  2. While it is said that images up to 10MB can be uploaded, it does not work like that
  3. CPU could be used more intense (queued) to downsize an image after the actual upload happens, instead of refusing image upload which is smaller than 10MB.

The focus in this report is on that the functionality does not correspond to the claims.


(Jeff Atwood) #10

This is an insanely small value. I think 1024kb is quite low for a maximum image file size, much less… anything smaller than that.

I think the real issue here is, you should allow larger images if you users want to upload images. Make room, buy more server storage space, etc. That or disallow uploading images altogether and force them to post images to imgur (or similar) first.


(Simeon) #11

I have an issue with this though. Many image hosting services don’t have upload size limits. So a person can upload a 100mb GIF, which then loads on our forum and burns through the users mobile data caps.

I’d like the image size restrictions to apply to even linked images. Maybe with a ‘click to load’ button replacing it.


(Stephen Chung) #12

The problem is, not all users even know the difference between JPEG and PNG, let along being able to resize and convert them before uploading.

Also, that are a lot of cases when a screen-shot is copied to the clipboard in PNG format (for example, FireFox’s new screen-shot feature). People are just gonna Ctrl-V to paste that photo into a message and fire away. They are not gonna take the time to convert and downsize.

Can there be a background low-priority job running that automatically resize these uploaded images to a particular maximum size?


(Jeff Atwood) #13

That is already the way it works.


(Sam Saffron) #14

A post was split to a new topic: Changing image width/height manually does not always work!


(Sam Saffron) #15

To me the OP looks like a feature request.

The request here is to add a second site setting.

Then we would have:

  • Maximum allowed upload size
  • Maximum allowed image size.

That way … you can allow 6MB uploads but force all images to 300kb by dropping quality.

Technically I think this is doable and probably an option we should offer.

The alternative of resizing on the client side is just a bit too flakey to get working properly.

@codinghorror thoughts?


(Jeff Atwood) #16

Pretty sure this already exists via site settings, cc @zogstrip @techAPJ


(Régis Hanol) #17

Yup, we already do that.

We don’t have a maximum allowed upload size site setting though. It’s only limited via NGINX.

And we also have another site setting to help downsize images: max image megapixels.


(Sam Saffron) #18

Yeah I think this is all covered now.

We try downsizing 3 times prior to creating the upload.

@meglio can we close this?


(Jeff Atwood) #19