使用asp.net中的文件上传进行视频上传

时间:2013-12-04 10:32:51

标签: c# asp.net ajax file-upload

如何使用asp.net中的文件上传来上传vedio。我已经尝试过这段代码,但它没有按预期工作

我的asp上传器

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

我有

 <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();
      }

我有像这样的ajax Vedio Uploader

   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;
        }
    }
  }
 }

代码中有什么问题吗?任何人都有想法上传视频?你的帮助对我意义重大

0 个答案:

没有答案