MVC文件上傳05-使用客戶端jQuery-File-Upload插件和服務端Backload組件自定義上傳文件夾

在零配置狀況下,文件的上傳文件夾是根目錄下的Files文件夾,如何自定義文件的上傳文件夾呢?css

 

MVC文件上傳相關兄弟篇:html

MVC文件上傳01-使用jquery異步上傳並客戶端驗證類型和大小 
MVC文件上傳02-使用HttpPostedFileBase上傳多個文件  
MVC文件上傳03-使用Request.Files上傳多個文件
MVC文件上傳04-使用客戶端jQuery-File-Upload插件和服務端Backload組件實現多文件異步上傳   jquery


□ 在web.config中配置git

   1:  <configuration>
   2:    <configSections>
   3:    ...
   4:    <section name="backload" type="Backload.Configuration.BackloadSection, Backload, Version=1.9.3.1, Culture=neutral, PublicKeyToken=02eaf42ab375d363" requirePermission="false" />
   5:    </configSections>
   6:    
   7:     <backload xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:name="urn:fileupload-schema" xsi:noNamespaceSchemaLocation="Web.FileUpload.xsd">
   8:      <fileSystem filesRoot="~/Uploads" />
   9:    </backload>
  10:   
  11:  </configuration>

Version能夠經過右鍵程序集屬性中查到。github

PublicKeyToken能夠經過反編譯器,好比Reflector查到。web

 

□ 註銷BackloadDemoController的Index方法bootstrap

   1:  using System.Web.Mvc;
   2:   
   3:  namespace MvcApplication6.Controllers
   4:  {
   5:      public class BackloadDemoController : Controller
   6:      {
   7:          // GET: /BackupDemo/
   8:          //public ActionResult Index()
   9:          //{
  10:          //    return View();
  11:          //}
  12:      }
  13:  }
  14:   

 

□ 讓BaseController繼承BackloadDemoController,並註銷Index方法異步

   1:  using System.Web.Mvc;
   2:   
   3:  namespace MvcApplication6.Controllers
   4:  {
   5:      public class BaseController : BackloadDemoController
   6:      {
   7:          //public ActionResult Index()
   8:          //{
   9:          //    return View();
  10:          //}
  11:      }
  12:  }

 

□ 讓HomeController繼承BaseControllerui

   1:  using System.Web.Mvc;
   2:   
   3:  namespace MvcApplication6.Controllers
   4:  {
   5:      public class HomeController : BaseController
   6:      {
   7:          public ActionResult Index()
   8:          {
   9:              return View();
  10:          }
  11:      }
  12:  }
  13:   


□ _Layout.cshtml視圖this

   1:  <!DOCTYPE html>
   2:  <html>
   3:  <head>
   4:      <meta charset="utf-8" />
   5:      <meta name="viewport" content="width=device-width" />
   6:      <title>@ViewBag.Title</title>
   7:      @Styles.Render("~/Content/css")
   8:      @Styles.Render("~/Content/themes/base/css")
   9:      @Styles.Render("~/bundles/fileupload/bootstrap/BasicPlusUI/css")
  10:      @Scripts.Render("~/bundles/modernizr")
  11:   
  12:  </head>
  13:  <body>
  14:      @RenderBody()
  15:   
  16:      @Scripts.Render("~/bundles/jquery")
  17:      @Scripts.Render("~/bundles/jqueryui")
  18:      @Scripts.Render("~/bundles/fileupload/bootstrap/BasicPlusUI/js")
  19:      @RenderSection("scripts", required: false)
  20:  </body>
  21:  </html>
  22:   


□ Home/Index.cshtml視圖

展開

 

□ 結果:

上傳2個文件:
8

 

此次,圖片上傳到了Uploads文件夾:
9

 

Uploads文件夾有剛上傳的2個文件:
10

 

□ 若是想讓web.config配置文件相對「乾淨」,能夠把與Backload相關的配置放到單獨的一個配置文件

web.config中能夠這樣:

   1:  <configuration>
   2:    <configSections>
   3:    ...
   4:    <section name="backload" type="Backload.Configuration.BackloadSection, Backload, Version=1.9.3.1, Culture=neutral, PublicKeyToken=02eaf42ab375d363" requirePermission="false" />
   5:    </configSections>
   6:    
   7:     <backload configSource="Web.Backload.config" />
   8:  </configuration>

 

根目錄下的Web.Backload.config能夠這樣:

   1:  <?xml version="1.0"?>
   2:  <backload storageContext="Filesystem" xsi:noNamespaceSchemaLocation="Web.Backload.xsd" xmlns:name="urn:backload-schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   3:    <fileSystem filesRoot="~/Uploads" />
   4:  </backload>

 

參考資料:
http://backload.org/ Backload官網
https://github.com/blackcity/Backload#examples Backload例子
http://nuget.org/packages/Backload/ nuget上的Backload

http://blueimp.github.io/jQuery-File-Upload/ jQuery File Upload官網
https://github.com/blueimp/jQuery-File-Upload/wiki  github上的jQuery File Upload介紹
https://github.com/blueimp/jQuery-File-Upload  github上的jQuery File Upload源碼

https://www.nuget.org/packages/JQueryFileUpload_Demo_with_Backload/  下載jQuery File Upload結合Backload的MVC案例

相關文章
相關標籤/搜索