This article is a mirror article of machine translation, please click here to jump to the original article.

View: 17441|Reply: 1

[ASP.NET] asp.net MVC's FineUploader upload component

[Copy link]
Posted on 11/12/2015 10:18:06 AM | | | |


Fine Uploader is a file upload component implemented with Ajax technology that supports drag-and-drop file uploads. It's easy to use, just introduce the corresponding CSS+Javascrip{filter}t into the page, and the rest is just server-side processing logic. There are already several language implementations in the download package it provides: ASP.NET, ColdFusion, Java, Node.js, Perl, PHP, Python.

Front Desk:
  1. <div id="fine-uploader"></div>
Copy code
js:
  1. $(function () {
  2.             $('#fine-uploader').fineUploader({
  3.                 request: {
  4.                     endpoint: '/Upload/ProcessUpload'
  5.                 },
  6.                 validation: {
  7.                     allowedExtensions: ['jpeg', 'jpg', 'png'],
  8.                     sizeLimit: 2097152
  9.                 },
  10.                 multiple: false,
  11.                 text: {
  12.                     uploadButton: '<div>上传头像</div>',
  13.                     dropProcessing: "(支持文件拖放上传,只能上传单张2M以下png、jpg、gif图片)"
  14.                 }
  15.             }).on('complete', function (event, id, fileName, responseJson) {
  16.                 if (responseJson.success) {
  17.                     
  18.                     //这里是上传成功之后的东西
  19.                 }
  20.             });
  21.             
  22.         });
Copy code
Background Code:
  1. [HttpPost]
  2.         public ActionResult ProcessUpload(string qqfile)
  3.         {
  4.             try
  5.             {
  6.                 string uploadFolder = "/Images/Temp/";
  7.                 string imgName = Guid.NewGuid().ToString("D");
  8.                 string imgType = Path.GetExtension(qqfile);
  9.                 string uploadPath =  Server.MapPath(uploadFolder);
  10.                 if (!Directory.Exists(uploadPath))
  11.                 {
  12.                     Directory.CreateDirectory(uploadPath);
  13.                 }
  14.                 using (var inputStream = Request.InputStream)
  15.                 {
  16.                     using (var flieStream = new FileStream(uploadPath + imgName + imgType, FileMode.Create))
  17.                     {
  18.                         inputStream.CopyTo(flieStream);
  19.                     }
  20.                 }
  21.                 //获取图片的宽度和高度
  22.                 //using (FileStream fs = new FileStream(@"1.jpg", FileMode.Open, FileAccess.Read))
  23.                 //{
  24.                 //    System.Drawing.Image image = System.Drawing.Image.FromStream(fs);
  25.                 //    string width = image.Width.ToString();
  26.                 //    string height = image.Height.ToString();
  27.                 //}  
  28.                 return Json(new { success = true, message = uploadFolder + imgName + imgType, width = 852, height =1136});

  29.             }
  30.             catch (Exception ex)
  31.             {
  32.                 return Json(new { fail = true, message = "上传失败!" });
  33.             }
  34.         }
Copy code
This is the js package: fineuploader.rar (11.47 KB, Number of downloads: 0, 售价: 2 粒MB)




Previous:Taobao and Tmall ended with sales exceeding 90 billion yuan on Double 11, and Jack Ma defeated JD.com and Suning as the winner
Next:Many websites in China are held by clientHold
Posted on 5/29/2019 1:58:07 PM |
Good resources How to download?
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com