【问题标题】:Upload Large Files from ASP .Net Application从 ASP .Net 应用程序上传大文件
【发布时间】:2011-01-17 02:05:02
【问题描述】:

我正在建立一个网站,我需要一个用户可以上传大型视频文件的页面,我已经创建了带有流媒体的 WCF 服务,但我正在从网页的 Button_Click 事件调用该 WCF 服务。

我已经使用下面提到的文章来创建 WCF 服务

WCF Streaming

我使用了流式传输,因为它应该是高效的并且不应该在服务器的内存中缓冲。

现在的问题

1) 我怀疑整个文件是否已上传到 Web 服务器,然后将其传输到 WCF 服务服务器...如果这是真的,那么我将无法利用流媒体以及 iis 和 Web 服务器如果用户上传大文件或多个用户正在上传文件,将很快关闭

2) 有没有其他有效的方法可以使用其他技术进行相同的操作

请帮帮我...

编辑:

如果在这种情况下我没有从 ASP .Net 代码调用 WCF 服务方法,它也会将字节传输到我使用 HTTPFox 检查过的 Web 服务器

我已经通过上传控件检查了上面的内容,并在 UI 上放置了一个按钮,该按钮的点击事件绑定到后面代码中的一种方法。

所以,我仍然对数据如何传输感到困惑

  1. 客户端计算机 - Web 服务器(ASP .Net 应用程序)- 服务服务器(WCF 服务)
  2. 客户端计算机 - 服务服务器(WCF 服务)

注意:如果我在 button_click 上放置一个调试点并上传 10 kb 文件,它会在不到 1 秒的时间内完成。但如果我要上传 50 mb 的文件,那么这需要时间。

我在 button_click 事件中放置了调用 WCF 服务的代码

【问题讨论】:

  • 我觉得标题应该是“Upload Large Files to ASP.NET Application”。

标签: asp.net wcf file-upload


【解决方案1】:

1) 我怀疑整个 文件被上传到网络服务器和 然后将其转移到 WCF 服务 服务器...如果这是真的,那么我不是 也可以利用流媒体 因为 iis 和 web 服务器将关闭 如果用户上传大文件,很快 或多个用户正在上传文件 目前的情况

不,你在这里混淆了一些东西。当您使用 WCF 流式传输来上传大文件时,文件是以块的形式发送的 - 以几 KB 大小的块为单位。 WCF 服务器 - 在 IIS 中运行或在 NT 服务或控制台应用程序中自托管 - 同时接收这些块并将它们写入磁盘,当它们到达时。

您不会“将整个文件上传到 Web 服务器”然后将其“传输”到 WCF 服务 - WCF 服务本身正在接收和处理文件 - 并且只有一次。

如果您自己托管 WCF 服务 - 在控制台应用程序、Winforms 应用程序或 Windows NT 服务中 - 甚至根本不涉及任何 IIS 或 Web 服务器。 WCF 自己处理所有这些。

使用 WCF 流式传输可能是最节省内存的方法之一,也是将大文件传输到服务器的最简单方法之一。

查看更多关于该主题的示例和博客文章:

【讨论】:

  • 你好 mark_s 我也有同样的想法,但你能解释一下我在编辑中解释的场景,我没有调用任何 WCF 服务,但整个文件仍在传输,这就是我的原因我感觉数据首先传输到 Web 服务器(ASP .Net App Server)
  • @Radhi:我不明白你到底想做什么......尝试将你的 WCF 服务代码放入程序集中,并编写你自己的自托管 - 一个简单的控制台应用程序就可以了。那么你绝对完全独立于任何网络服务器/IIS 或任何东西。这行得通吗?
  • 实际上它是一个上传视频的网站,用户可以在两者之间分享它们,所以我希望用户可以访问视频上传页面并能够从该页面上传。那么,是否可以在控制台应用程序中托管 wcf 服务并从客户端调用它(因为我对客户端计算机没有任何控制权)是否可以从 jquery 调用 WCF 服务来上传文件?请指导我...
  • @Radhi,您解决了从 ASP.NET 站点上传文件的问题吗?如果可以,请写下建议吗?
【解决方案2】:

这是您最好的解决方案,我和您走的路相同,得出的结论是 ftp 更容易并且可以完美运行。下面是一些示例代码:

首先得到这个库,完美运行:

http://www.freedownloadscenter.com/Programming/Components_and_Libraries/BytesRoad_NetSuit_Library.html

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.IO;
    using System.Configuration;
    using System.Collections.Specialized;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Net;
    using BytesRoad.Net.Ftp;





    namespace GetMedia
    {
        class Program
        {

            static void Main(string[] args)
            {

                string strPath;
                string strThumbPath;
                string strThumbLocalPath;
                string strURLRoot;
                string strVideoFile;
                string strThumbfile;
                string strError;


                BizetDataDataContext db = new BizetDataDataContext();
                VCMediaDataContext db2 = new VCMediaDataContext();
                db.Connection.ConnectionString = Settings.Default.ConnectionString;
                db2.Connection.ConnectionString = Settings.Default.ConnectionString;

                //Temp Folder
                strPath = Settings.Default.TempFolder;
                strThumbLocalPath = Settings.Default.ThumbPath;

download video and thumb
            //then upload to mediaserver

                IQueryable<BizetInfo> custQuery =
                from bizet in db.BizetInfos
                where bizet.Path != null
                select bizet;

                foreach (BizetInfo objbizet in custQuery)
                {
                    //Grab filename and path


                    strVideoFile = Path.GetFileName(objbizet.Path).Replace("%20", "_").Replace("_medium", "").Replace(" ", "_");
                    strThumbfile = Path.GetFileName(objbizet.Path).Replace("%20", " ").Replace("_medium.wmv", ".mpg.png");
                    strURLRoot = objbizet.Path.Replace(Path.GetFileName(objbizet.Path), "");
                    strThumbPath = strURLRoot + strThumbfile;



                    strError = "";

                    try
                    {



                        wsViaCastMedia.MediaTransferSoapClient ws = new wsViaCastMedia.MediaTransferSoapClient();

                        System.Net.WebClient wc = new System.Net.WebClient();
                        //connect to Bizet
                        Console.WriteLine("Starting spotID: " + objbizet.SPOTID.ToString().Trim());
                        Console.WriteLine("connected to ws");
                        Console.WriteLine("Downloading Video File");

                        //Download  Video
                        wc.DownloadFile(objbizet.Path, strPath + strVideoFile);

                        //Download Thumb
                        Console.WriteLine("Downloading Thumb File");

                        wc.DownloadFile(strThumbPath, strThumbLocalPath + strThumbfile);

                        wc.Dispose();

                        //new ftp code

                        BytesRoad.Net.Ftp.FtpClient f = new BytesRoad.Net.Ftp.FtpClient();
                        f.PassiveMode = false;

                        f.Connect(999999999, "IPADDRESS OF FTP", 21);
                        f.Login(999999999, "", "");

                        try
                        {
                            f.ChangeDirectory(999999999, objbizet.CLIENTID.ToString().Trim());
                        }
                        catch (Exception e)
                        {
                            f.CreateDirectory(999999999, objbizet.CLIENTID.ToString().Trim());
                            f.ChangeDirectory(999999999, objbizet.CLIENTID.ToString().Trim());
                            Console.WriteLine(e);
                        }

                        f.PutFile(999999999, strVideoFile, "E:\\temp\\" + strVideoFile);



                        Console.WriteLine("Transfer of Video File " + objbizet.Path + " Complete");
                        //response.Close();
                        f.Disconnect(999999999);

                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        strError = e.ToString();
                    }
                    finally //Update Data
                    {
                        //check if spot Exists ///need to fix

                        //var myquery = from m in db2.Medias
                        //              where m.SpotID == Convert.ToInt32(objbizet.SPOTID.Trim())
                        //              select m;
                        //foreach (var mm in myquery)
                        //{
                        //    //db2.DeleteMedia(objbizet.SPOTID.Trim());
                        //}

                        if (strError == "")
                        {
                            db2.AddMedia(Convert.ToInt32(objbizet.SPOTID), objbizet.Title, objbizet.Keywords, objbizet.Path, strVideoFile, objbizet.CLIENTNAME, Convert.ToInt32(objbizet.CLIENTID), objbizet.SUBCATEGORYNAME, Convert.ToInt32(objbizet.SUBCATEGORYID), Convert.ToDecimal(objbizet.PRICE), strThumbfile, objbizet.Description);
                        }
                        else
                        {
                            db2.AddMedia(Convert.ToInt32(objbizet.SPOTID), "Under Maintenance -  " + objbizet.Title, objbizet.Keywords, objbizet.Path, strVideoFile, objbizet.CLIENTNAME, Convert.ToInt32(objbizet.CLIENTID), objbizet.SUBCATEGORYNAME, Convert.ToInt32(objbizet.SUBCATEGORYID), Convert.ToDecimal(objbizet.PRICE), strThumbfile, objbizet.Description);
                        }
                    }




                }
                //dispose
                db.Dispose();
                db2.Dispose();

            }

    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-21
    • 2013-11-11
    • 2021-09-09
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多