locked
Query Image Size Prior to Uploading? RRS feed

  • Question

  • User439975351 posted

    Hi All,

    I have spent the morning Googling around to find an answer to a frustrating problem regarding image uploads.

    I want to set a limit on each image uploadeed to the website (say 10Mb). I have added the relevant maxRequestLength to the web.config therefore files of up to 10Mb are handled perfectly.

    The problem - When a file of greater than 10Mb is submitted I simply receive a Connection Reset Error.

    Does anyone know how to catch/handle this problem? It seems that the server simply disconnects prior to hitting any C# code. (So this might be an IIS issue, sorry for posting here if it is).

    I would have thought this was a common problem with many DSLR cameras produces large files these days but I cannot find a conclusive way to deal with this :(

    Any help, as always, greatly appreciated! :)

    Saturday, March 9, 2013 8:59 AM

Answers

  • User-434868552 posted

    @ 1jus      welcome to forums.asp.net

    You can not interrogate the file system on your end user's machine ... you could create code that runs on your end users machine but then you would need your end users permission to install that code ...

    you best option may be to have a help page that explains to novice end users how they could determine the file size before choosing it to be uploaded ... you would then tell them your limit ...

    TIMTOWTDI =. there is more than one way to do it

    you could use a strategy like this:

    (a) determine average size ... for purpose of this example, let's say it's 3.5MB

    (b) set your limit lower, let's say 5MB

    (c) if the upload fails, have an error page where you (1) tell your end user you do not accept files larger than 10MB .... (2) instruct your end user how to check the file size ... (3) set your limit for that upload ONLY to 10MB.     n.b.:  if your end user tries to feed you a file bigger that 10MB, after your upload fails, save the end user's ip address and file name and do not let your end user upload that file again

    (d) only allow authenticated and authorized end users to upload files.

    Remember, browsers have built in safety as do operating systems ... that's what's happening to you and it's a good thing because it protects both you and your end user.

    g.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 9, 2013 9:14 AM
  • User439975351 posted

    Thanks for the reply Gerry :)

    I'm thiniking that the server is closing the connection rather than the browser? If this is the case then would it be safe to assume that IIS/ASP.net "knows" that the image submitted exceeds the configured maximum? From that it would be good to know what process IIS or AP.net uses to say "Hey Im closing the connection" and tap into that to handle it in a more informative manner to the user.

    As a work around I was thinking of reducing the IIS limites to 10Mb (from 30Mb on IIS8) and handling the 404.13.

    http://support.microsoft.com/kb/942074 

    I'm in the process of testing this in a VM as I type ;-)

    I really want to find a solid way to nail this issue but it's proving quite sticky! :(

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 9, 2013 9:25 AM

All replies

  • User-434868552 posted

    @ 1jus      welcome to forums.asp.net

    You can not interrogate the file system on your end user's machine ... you could create code that runs on your end users machine but then you would need your end users permission to install that code ...

    you best option may be to have a help page that explains to novice end users how they could determine the file size before choosing it to be uploaded ... you would then tell them your limit ...

    TIMTOWTDI =. there is more than one way to do it

    you could use a strategy like this:

    (a) determine average size ... for purpose of this example, let's say it's 3.5MB

    (b) set your limit lower, let's say 5MB

    (c) if the upload fails, have an error page where you (1) tell your end user you do not accept files larger than 10MB .... (2) instruct your end user how to check the file size ... (3) set your limit for that upload ONLY to 10MB.     n.b.:  if your end user tries to feed you a file bigger that 10MB, after your upload fails, save the end user's ip address and file name and do not let your end user upload that file again

    (d) only allow authenticated and authorized end users to upload files.

    Remember, browsers have built in safety as do operating systems ... that's what's happening to you and it's a good thing because it protects both you and your end user.

    g.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 9, 2013 9:14 AM
  • User439975351 posted

    Thanks for the reply Gerry :)

    I'm thiniking that the server is closing the connection rather than the browser? If this is the case then would it be safe to assume that IIS/ASP.net "knows" that the image submitted exceeds the configured maximum? From that it would be good to know what process IIS or AP.net uses to say "Hey Im closing the connection" and tap into that to handle it in a more informative manner to the user.

    As a work around I was thinking of reducing the IIS limites to 10Mb (from 30Mb on IIS8) and handling the 404.13.

    http://support.microsoft.com/kb/942074 

    I'm in the process of testing this in a VM as I type ;-)

    I really want to find a solid way to nail this issue but it's proving quite sticky! :(

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 9, 2013 9:25 AM
  • User-434868552 posted

    1jus    ... you're welcome ...

    you could try using Eric Lawrence's free and fantastic tool "Fiddler2"; by studying the headers that Fiddler2 captures, you may be able to know whether the informance you'd like to have is even available ... http://fiddler2.com

     ... if you can not find anything useful, and if you have a lot of patience, you could try WireShark (http://wireshark.org/) which is also free ...

    --gerry

    P.S.:  a TCP/IP header will tell you the size of an individual packet BUT i do not know whether you get a header that gives you a head's up on the total number of bytes to flow to the server.

    Wednesday, March 27, 2013 1:20 PM
  • User439975351 posted

    Thanks again Gerry, I have handled the 404.13 gracefully which to the user seems friendly enough. Technically its a shame that I cant handle this more efficiently.

    Tuesday, April 9, 2013 4:58 PM