0

我有一个 MVC asp.net 应用程序可以在我的应用程序的一个文件夹中上传多个图像。它只是上传图像,压缩并将其保存到一个文件夹并将其缩略图保存到另一个文件夹。上传是在后台进行的,因为我可以在我的应用程序中执行其他工作。

上传大量图片需要一些时间。所以我需要在浮动对话框或弹出窗口中显示上传图像的状态作为进度条,当上传完成时,我应该得到一个警报,告诉过程已经完成。

在视图中

<form action="" method="post" enctype="multipart/form-data">
  @Html.Label("Select the property : ");
  @Html.DropDownList("Address", new SelectList(ViewBag.Address as System.Collections.IEnumerable), "---Select---",new { id = "add"})

  <label for="file">Filename:</label>
  <input type="file" name="files" id="file" multiple="true"/>
  <input type="submit" />

在控制器中

 [HttpPost]
        public ActionResult Index(HttpPostedFileBase[] files, FormCollection c)
        {
            int no = 0;
            string path = Path.Combine(Server.MapPath("~/Images"), c["Address"].Replace(' ', '_'));
            string fn = "";
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            else
                no = Directory.GetFiles(path).Length;
            foreach (var file in files)
            {
                string fname = "img_" + no++ + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                fn = Path.Combine(path, fname);
                Thread.Sleep(10000);

                ImageCodecInfo jpgEncoder = null;
                ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
                foreach (ImageCodecInfo codec in codecs)
                {
                    if (codec.FormatID == ImageFormat.Jpeg.Guid)
                    {
                        jpgEncoder = codec;
                        break;
                    }
                }
                var image1 = System.Drawing.Image.FromStream(file.InputStream, true, true);
                if (jpgEncoder != null)
                {
                    Encoder encoder = Encoder.Quality;
                    EncoderParameters encoderParameters = new EncoderParameters(1);

                        long quality = 20;
                        EncoderParameter encoderParameter = new EncoderParameter(encoder, quality);
                        encoderParameters.Param[0] = encoderParameter;
                        FileStream ms = new FileStream(fn, FileMode.Create, FileAccess.Write);
                        image1.Save(ms, jpgEncoder, encoderParameters);
                        ms.Flush();
                        ms.Close();
                }



                using (var image = System.Drawing.Image.FromStream(file.InputStream, true, true)) /* Creates Image from specified data stream */
                {
                    using (var thumb = image.GetThumbnailImage(
                         50, /* width*/
                         60, /* height*/
                         () => false,
                         IntPtr.Zero))
                    {
                        var jpgInfo = ImageCodecInfo.GetImageEncoders().Where(codecInfo => codecInfo.MimeType == "image/png").First(); /* Returns array of image encoder objects built into GDI+ */
                        using (var encParams = new EncoderParameters(1))
                        {
                            string pa = Path.Combine(path, "Thumb");
                            if (!Directory.Exists(pa))
                            {
                                Directory.CreateDirectory(pa);
                            }
                            string outputPath = Path.Combine(pa, fname);
                            long quality = 100;
                            encParams.Param[0] = new EncoderParameter(Encoder.Quality, quality);
                            thumb.Save(outputPath, jpgInfo, encParams);
                        }
                    }
                }

            }

            return RedirectToAction("Index");

}

谁能帮我在我的应用程序的浮动对话框或弹出窗口中制作进度条?

4

0 回答 0