首页 新闻 搜索 专区 学院

extjs在做文件上传显示进度条时,如果文件太大有时候他的task任务取消不掉求指教

0
悬赏园豆:15 [已关闭问题] 关闭于 2014-06-18 17:52
  <form id="form1" runat="server">
    
    </div>
        <ext:ResourceManager ID="run1" runat="server">
        </ext:ResourceManager>
   <ext:Panel ID="pan1" runat="server">
        <Items>
        
        <ext:FileUploadField ID="fl1" Width="300"  Icon="FilmAdd" runat="server">
        
        </ext:FileUploadField>
        <ext:Button runat="server" ID="btnSub" Text="提交">
        
        <DirectEvents >
           <Click OnEvent="btnSubClick" />
        </DirectEvents>
        </ext:Button>
        </Items>
        
        
   </ext:Panel>
    <ext:TaskManager ID="TaskManager1" runat="server">
        <Tasks>
            <ext:Task 
                TaskID="Task1"
                Interval="5000" 
                AutoRun="false" >
                <DirectEvents>
                    <Update OnEvent="RefreshProgress"  />
                </DirectEvents>                    
            </ext:Task>
        </Tasks>
    </ext:TaskManager>
    </form>
 protected void btnSubClick(object sender, DirectEventArgs e)
        {
            X.Msg.Show(new MessageBoxConfig
            {
                Title = "请稍候",
                Message = "正在上传",
                ProgressText = ".",
                Width = 300,
                Progress = true,
                Closable = false,
                AnimEl = this.btnSub.ClientID,

            });
            this.StartLongAction();

        }
        private void StartLongAction()
        {

            this.Session["complete"] = 0;
            ThreadPool.QueueUserWorkItem(LongAction);
            this.TaskManager1.StartTask("Task1");
        }

        private void LongAction(object state)
        {
            //Common.CommonHelper.UpLoadFile(FileUploadField3,"/UpLoadImages",Convert.ToInt32(this.Session["complete"]),Convert.ToInt32(this.Session["allByte"]));

            if (fl1.HasFile)
            {
                string openPath = "";

                if (fl1.PostedFile != null && fl1.PostedFile.ContentLength > 0)
                {
                    openPath = fl1.PostedFile.FileName;
                   
                    string strPictureName = "";//上传后的图片名,以当前时间为文件名,确保文件名没有重复

                    if (!string.IsNullOrEmpty(openPath))
                    {
                        try
                        {
                            string strFileName = System.IO.Path.GetFileName(openPath);
                            strPictureName = DateTime.Now.Ticks.ToString() + strFileName;
                            string strMapPath = Server.MapPath("~/media/");
                            string strPath = strMapPath + strPictureName;
                            //文件总大小this.Session["allByte"]= fl1.PostedFile.ContentLength;
                  

                            FileStream fsreader = new FileStream(openPath, FileMode.Open);
                            FileStream fswriter = new FileStream(strPath, FileMode.Create);
                            int readbyte = Convert.ToInt32(this.Session["complete"]);

                            
                            
                            using (fsreader)
                            {
                                using (fswriter)
                                {
                                    byte[] byts = new byte[1024];
                                    while (true)
                                    {
                                       int b = fsreader.Read(byts, 0, byts.Length);
                                        readbyte += b;
                                        this.Session["complete"] = readbyte;
                                        if (b <= 0)
                                        {
                                            break;
                                        }
                                        fswriter.Write(byts, 0, b);
Thread.Sleep(1000); } } } }
catch (Exception ex) { ExtNet.Msg.Alert("提示", ex.Message).Show(); } } } } this.Session.Remove("complete"); this.Session.Remove("allBtte"); } protected void RefreshProgress(object sender, DirectEventArgs e) { if (this.Session["complete"] != null && this.Session["allByte"] != null) { float progress = float.Parse(this.Session["complete"].ToString()); float all = float.Parse(this.Session["allByte"].ToString()); X.Msg.UpdateProgress(progress / all, string.Format("已上传{0}%", Convert.ToInt32((progress / all) * 100))); } else { this.TaskManager1.StopTask("Task1"); X.MessageBox.Hide(); this.run1.AddScript("Ext.Msg.notify('恭喜你', '已上传成功!');"); } }
问题补充:

文件一大上传完成后,task还在不停地刷新RefreshProgress()方法,而且停止不掉,不清楚问什么,求大牛指教

zppiao的主页 zppiao | 初学一级 | 园豆:190
提问于:2012-11-17 10:40
< >
分享
所有回答(1)
0

上传大文件建议使用 分块上传,flash,silverlight 都有这样的插件。

上传完成后,task还在不停地刷新RefreshProgress()。 这个问题,调试下是 服务器端的问题还是客户端的问题。也有可能是连接超时了。

geass.. | 园豆:1777 (小虾三级) | 2012-11-18 20:25

我调试了很多次都是在RefreshProgress()里,不清楚已经STOP掉了  还在刷新,不知道怎么看是那里的问题,本人新手能否教教我

支持(0) 反对(0) zppiao | 园豆:190 (初学一级) | 2012-11-18 20:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册