1

How to upload vedio using file upload in asp.net. I have tried this piece of code but it is not working as desired

My asp Uploader

    <input id="videoToUpload" type="file" size="45" name="vedioToUpload" onchange="return validateVideoToUpload()" />

in Script I have

 <script type="text/javascript">
  function ajaxFileUpload() {
    $("#FileLoading")
    .ajaxStart(function () {
     $(this).show();
     })
    .ajaxComplete(function () {
    $(this).hide();
   });

    $.ajaxFileUpload
    (
    {
        url: '<%=ResolveClientUrl("~/UserControls/VideoGallery/AjaxVideoUploader.ashx?FSPath=") + FileStoragePath %>',
        secureuri: false,
        fileElementId: 'videoToUpload',
        dataType: 'json',
        data: { name: 'logan', id: 'id' },
        success: function (data, status) {
            if (typeof (data.error) != 'undefined') {
                if (data.error != '') {
                    alert(data.error);
                } else {
                    alert(data.msg);
                }
            }
        },
        error: function (data, status, e) {
            alert(e);
        }
    }
  )
    return false;
 }

function validateVideoToUpload() {
    var uploadcontrol = document.getElementById('videoToUpload').value;

    if (uploadcontrol.length > 0) {

            ajaxFileUpload();
      }

I have the ajax Vedio Uploader like this

   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Web;
   using System.Web.SessionState;
   using System.IO;

   namespace WebBreakAwayAdventures.UserControls.VideoGallery
   {
   /// <summary>
   /// Summary description for AjaxVideoUploader
   /// </summary>
   public class AjaxVideoUploader : IHttpHandler, IRequiresSessionState
   {

    public void ProcessRequest(HttpContext context)
    {
        try
        {
            if (context.Request.Files.Count > 0)
            {
                string msg = "{";
                if (context.Request.QueryString["FSPath"] != null)
                {
                    context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    context.Response.BufferOutput = false;

                    // Check Normal Video Files storage path and if Directory is not available then create that
                    DirectoryInfo diTemp = new DirectoryInfo(Path.Combine(context.Server.MapPath(context.Request.QueryString["FSPath"].ToString()), "temp"));

                    if (!diTemp.Exists)
                    {
                        diTemp.Create();
                    }

                    // Create Random unique file name using last write time into the directory
                    string filename = Path.Combine(diTemp.FullName, String.Format("file{0}{1}", diTemp.LastWriteTime.Ticks + 1L, Path.GetExtension(context.Request.Files[0].FileName)));

                    // Save video file in the temp directory
                    context.Request.Files[0].SaveAs(filename);

                    HttpContext.Current.Session["ucVideoUploaderFileName"] = filename;

                    msg += string.Format("error:'{0}',\n", string.Empty);
                    msg += string.Format("msg:'{0}'\n", "Upload completed.");
                }
                else
                {
                    msg += string.Format("error:'{0}',\n", string.Empty);
                    msg += string.Format("msg:'{0}'\n", "Please provide file storage path !");
                }
                msg += "}";
                context.Response.Write(msg);
            }
        }
        catch (Exception ex)
        {
        }
    }

    public bool IsReusable
    {
        get
        {
            return true;
        }
    }
  }
 }

is there something wrong in the code? any one has any idea to upload video ? Your Help means a lot to me

OlivierH
  • 3,875
  • 1
  • 19
  • 32
Arunesh
  • 287
  • 6
  • 18
  • increase the max upload file size must change. [See this page](http://stackoverflow.com/questions/3853767/maximum-request-length-exceeded) – M.Rahmani Nov 08 '15 at 06:50

0 Answers0