SlickUpload
Welcome Guest Search | Active Topics | Log In | Register

Graceful error handling with IUploadLengthFilter Options
Eeeeeeeeee
#1 Posted : Monday, March 29, 2010 9:22:32 AM
Rank: Newbie

Groups: Registered

Joined: 3/24/2010
Posts: 6

Hi,

I'm trying to configure SlickUpload to handle files that exceed the size specified in web.config but I cant find any examples that show how to do this.

So far I can see that IUploadLengthFilter is probably what I want to use but does someone have an example available that shows how I can implement an error message similar to the image you have on your homepage? (http://krystalware.com/images/graceful-error-handling.png)

Also, from what I've seen on the forum it's not possible to put a limit on each individual file, only the entire upload. I'm not sure if these posts are relevant to the latest version of SlickUpload or if it's now possible to limit individual filesize e.g. we want our users to be able to upload up to 3 files, each up to 5Mb. It is now possible to handle this using as single SlickUpload with MaxFiles="3"?

Thanks

Axosoft
#2 Posted : Tuesday, March 30, 2010 11:19:27 AM
Rank: Administration


Groups: Administrators

Joined: 7/7/2005
Posts: 1,586
Location: Scottsdale, AZ

It's not currently possible to limit each individual file size before the upload starts. The browser doesn't pass up file length information, only the content-length of the entire request. You can access the file length of each file after the upload is complete and reject the file at that point.

Uploads also have to fit in the maxRequestLength setting in web.config -- this is a hard limit on the length of the request. If you are trying to allow uploads to the SlickUpload handler to be larger, but limit the requests to the rest of the application, you can do this by using location based configuration just for the SlickUpload handler. Something like this:

  <location path="SlickUpload.axd">
    <slickUpload>
      <uploadParser handleRequests="true" />
    </slickUpload>
    <system.web>
      <httpRuntime maxRequestLength="2024000" executionTimeout="300"/>
    </system.web>
    <system.webServer>
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="2072576000"/>
        </requestFiltering>
      </security>
    </system.webServer>
  </location>

Because the setting for increased maxRequestLength is inside the location tag for the SlickUpload.axd handler, it will only apply to SlickUpload uploads. The rest of the application will continue to have the default maxRequestLength.

To address your situation with the 5 mb per file, with a max of 3 files, I'd recommend this:

  • Set your maxRequestLength to 15 mb (or slightly more to accommodate the request encoding overhead)
  • In the UploadComplete event, check the UploadStatus.Reason property. If this is UploadTerminationReason.MaxRequestLengthExceeded, the entire request was too large and the upload was rejected. Display an appropriate message.
  • If not, loop through the files. If a file is larger than 5mb, delete it and display the appropriate message for that file.

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.