This project has moved. For the latest updates, please go here.

HttpHandler for Turbo upload

To manage your upload using the Turbo service you have to create a new Handler for your project. (follow the example)

 

public class UploadGallery : OmidID.IO.SaveMedia.Handler.TurboUpload, System.Web.SessionState.IRequiresSessionState {

        protected override OmidID.IO.SaveMedia.SaveUploadFile GetSaveUploadFile() {
            // Return your configuration 
            // if you not implement this line the service use default save setting.
            return new OmidID.IO.SaveMedia.SaveUploadFile("UserGallery");
        }

        protected override void OnSaved(OmidID.IO.SaveMedia.Models.UploadInfo info) {
            base.OnSaved(info);

            // here you can insert a new record to your database
            // this is the example

            //*******************************************
            // use http://efmembership.codeplex.com     *
            //*******************************************
            
            //var userId = (int)System.Web.Security.Membership.GetUser().ProviderUserKey;
            //var gallery = repository.GetGalleryByName(userId, QueryString["GalleryID"]);
            //var photo = new Models.UserPhoto() {
            //    CreateOn = DateTime.Now,
            //    GalleryID = gallery.GalleryID,
            //    IPAddress = Worker.GetRemoteAddress(),
            //    Name = Path.GetFileNameWithoutExtension(info.FileName),
            //    Type = 1,
            //    Url = "~/UserGallery/{0}/" + Path.GetFileNameWithoutExtension(info.FileName) + ".jpeg",
            //    UserID = userId
            //};
        }

    }

I always save my url like "~/UserGalley/{0}/MyPic.jpeg" in database because i'll have choice to select the image size easily with string.Format.
There are 4 virtual method to receive the events

 

Method(s) Description
OnUploaded When upload completed
OnUpdate During upload status change this method will be fire up
OnSaving After OnUploaded file going to save
OnSaved After file will saved from temp file to new file

 

Now in the web.config web have to create new HttpHandler:

If you are using the IIS6 or Developer tools you have to add the HttpHandler to system.web section like this:

 

<configuration>
  <system.web>
    <!-- IIS <= 6 Only Or developer tools -->
    <httpHandlers>
      <add verb="POST" validate="false" path="GalleryUpload.axd" type="MvcApplication1.Handlers.UploadGallery" />
      <add verb="GET" path="GetUploadStatus.axd" validate="false" type="OmidID.IO.SaveMedia.Handler.JsonUploadInfo" />
    </httpHandlers>
  </system.web>
</configuration>

 

For IIS7 or higher you have to set the maximum size of security and also set the validate false.
When you use the IntegratedMode in IIS7 you must remove the httpHandlers from system.web and add them to system.webServer section

 

<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- Allow the IIS7 to big size request -->
        <requestLimits maxAllowedContentLength="2147483647"></requestLimits>
      </requestFiltering>
    </security>

    <!-- IIS > 7 Only (Integrated Mode) -->
    <handlers>
      <remove name="UrlRoutingHandler" />
      <add name="GalleryUpload" verb="POST" path="GalleryUpload.axd" preCondition="integratedMode" type="MvcApplication1.Handlers.UploadGallery" />
      <add name="GetUploadStatus" verb="GET" path="GetUploadStatus.axd" preCondition="integratedMode" type="OmidID.IO.SaveMedia.Handler.JsonUploadInfo" />
    </handlers>
    
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

In the handlers section you can see the GetUploadStatus.axd, web are use this for javascript to get upload information such as percent, total received, upload speed, time remaining,...

Last edited Jul 28, 2011 at 7:54 AM by OmidID, version 2

Comments

No comments yet.