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:
- <div id="fine-uploader"></div>
Copy code js:
- $(function () {
- $('#fine-uploader').fineUploader({
- request: {
- endpoint: '/Upload/ProcessUpload'
- },
- validation: {
- allowedExtensions: ['jpeg', 'jpg', 'png'],
- sizeLimit: 2097152
- },
- multiple: false,
- text: {
- uploadButton: '<div>上传头像</div>',
- dropProcessing: "(支持文件拖放上传,只能上传单张2M以下png、jpg、gif图片)"
- }
- }).on('complete', function (event, id, fileName, responseJson) {
- if (responseJson.success) {
-
- //这里是上传成功之后的东西
- }
- });
-
- });
Copy code Background Code:
- [HttpPost]
- public ActionResult ProcessUpload(string qqfile)
- {
- try
- {
- string uploadFolder = "/Images/Temp/";
- string imgName = Guid.NewGuid().ToString("D");
- string imgType = Path.GetExtension(qqfile);
- string uploadPath = Server.MapPath(uploadFolder);
- if (!Directory.Exists(uploadPath))
- {
- Directory.CreateDirectory(uploadPath);
- }
- using (var inputStream = Request.InputStream)
- {
- using (var flieStream = new FileStream(uploadPath + imgName + imgType, FileMode.Create))
- {
- inputStream.CopyTo(flieStream);
- }
- }
- //获取图片的宽度和高度
- //using (FileStream fs = new FileStream(@"1.jpg", FileMode.Open, FileAccess.Read))
- //{
- // System.Drawing.Image image = System.Drawing.Image.FromStream(fs);
- // string width = image.Width.ToString();
- // string height = image.Height.ToString();
- //}
- return Json(new { success = true, message = uploadFolder + imgName + imgType, width = 852, height =1136});
- }
- catch (Exception ex)
- {
- return Json(new { fail = true, message = "上传失败!" });
- }
- }
Copy code This is the js package:
fineuploader.rar
(11.47 KB, Number of downloads: 0, 售价: 2 粒MB)
|