刚刚做了个文件上传功能,拿来分享一下!(MVC架构及传统架构通用)

刚刚做了个文件上传功能,拿来分享一下!(MVC架构及传统架构通用),第1张

文件上传无论在软件还是在网站上都十分常见,我今天再把它拿出来,讲一下,主要讲一下它的设计思想和实现技术,为了它的通用性,我把它做在了WEB.Service项目里,即它是针对服务器的,它的结构是关联UI(WEB)层与Service层(BLL)的桥梁.

结构

上传基类:

上传文件的接口规范:

接口的实现:

UI层调用WEB.Service层的上传功能:(附代码)

  public class FileUploadController : Controller

    {

 

       WEB.Services.IFileUpload iFileUpload = null;

        public FileUploadController()

        {

            iFileUpload = new WEB.Services.FileUpload();

        }

        #region 文件上传

 

        public ActionResult uploadheadpic()

        {

            return View();

        }

        [HttpPost]

        public ActionResult uploadheadpic(FormCollection formcollection)

        {

            if (Request.Files.Count > 0)

            {

                HttpPostedFileBase file = Request.Files[0];

                Entity.Commons.VMessage vm = iFileUpload.Image(WEB.Services.UpLoadType.DownloadUrl, file);

                if (vm.IsComplete)

                    TempData["PicUrl"] = "{result:true,msg:\"" + vm[0].Replace("\"", "") + "\"}";

                else

                    TempData["PicUrl"] = "{result:false,msg:\"" + vm[0].Replace("\"", "") + "\"}";

            }

            return View();

        }

        #endregion

 

    }

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/2081743.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-07-22
下一篇 2022-07-22

发表评论

登录后才能评论

评论列表(0条)

保存