• 大小: 9KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: 其他
  • 标签:

资源简介

这是我总结了多次写出来的代码,可以支持同时上传多个不同类型的文件,如果包括图片将会自动压缩,避免过大的图片上传到服务器。

资源截图

代码片段和文件信息

using RCSCloud.Models;
using RCSCloud.Tools;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

 
    public class DefaultController : Controller
    { 
        //上传附件的路径
        const string path = “/path/upl/fj“;
        public async Task Uploadbase64Files()
        {
            //保存文件的路径
            string path2 = Tool_HY.GetHYBH == 0 ? ToolDateTime.GetDateTimeNumber() : Tool_HY.GetHYBH.ToString();
            string savepath = $“{path}/{path2}“;

            //上传成功的文件
            IList files = new List();
            string error = string.Empty;
            string base64 = Request.Form[“AttachmentFile“];
            string title = Request.Form[“AttachmentFiletitle“];

            savepath = $“{savepath}/{ToolDateTime.GetDate()}/“;

            //物理路径
            string RootDir = Server.MapPath(savepath);
            return await Task.Run(() =>
            {
                if (base64 != null)
                {
                   JsonReturn  res = ToolImg.base64ToImage(base64 title savepath RootDir: RootDir);
                    if (res.state == true)
                    {
                        files.Add(new
                        {
                            res.path//路径
                            res.icon//图标
                            res.file//文件名
                        });
                    }
                }

                //其他文件
                HttpPostedFilebase item = null;
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    try
                    {
                        item = Request.Files[i];
                        //icon= extent path =$“{path}{fileName}“  file = fileName
                        JsonReturn res = ToolUpload.Upload(item savepath string.Format(“{0}“ Tool_HY.GetHYZH) extension: ToolRegex.all_File);
                        if (res.state == false)
                        {
                            return Json(res);
                        }

                        // JsonReturn res = ToolUpload.UploadHY_ZZ(item $“/upl/fj/{path}“ string.Format(“{0}“ Tool_HY.GetHYBH));
                        if (res.state == true)
                        {
                            files.Add(new
                            {
                                res.path//路径
                                res.icon//图标
                                res.file//文件名
                            });
                        }

                    }
                    catch (Exception ex)
                    {
                        error = $“{error}{ex.Message}“;
                    }
                }
                //dynamic res = ToolUpload.Upload(Attach

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件         366  2019-01-24 17:12  有使用上的问题请联系我.txt
     文件        1599  2018-09-02 11:17  JsonReturn.cs
     文件        3394  2019-01-24 14:24  ToolImg.cs
     文件        5355  2019-01-24 17:07  ToolUpload.cs
     文件       10096  2019-01-24 16:57  perfile_upload.js
     文件        3357  2019-01-24 17:06  DefaultController.cs

评论

共有 条评论