WebImage maximum size, file formats allowed etc

479 views Asked by At

I am using MVC WebImage helper

var image = WebImage.GetImageFromRequest();

It seems like the image is only allowed in image formats and there is a maximum size that is allowed set on the image.

for example, if I try to upload an "image" with extension .exe, it will be the same as

if (image == null)

which clearly isn't true, but WebImage helper seems to mark all non-image formats as null.

and if i try to upload an image that is too large, it will throw an error even though I didn't set any restrictions on the size of the image.

So my question

  1. What is the maximum allowed upload size? Is it something related to WebImage or is it related to something else(Browser, IIS etc)? if it is related to WebImage, how do I set it manually.
  2. What are the allowed formats? Where is the documentation? I've checked all over the place.
1

There are 1 answers

0
teo van kot On BEST ANSWER

First: Maximum file size define on the WebServer level. So if you want to change it the best way for whole application is to change it in Web.config, maxRequestLength. Ex:

<system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483647" />
      </requestFiltering>
    </security>
</system.web>

Second: The WebImage helper will attempt to return an image from any file that has an image MIME type.

So if you talking about extensions.

Following file types are accepted: ".jpg", ".png", ".bmp", & ".gif"

Following file types are not supported: ".ico", any non-image related file extension.