zoukankan      html  css  js  c++  java
  • 上传文件net core

    https://blog.csdn.net/qq_32688731/article/details/100924211

    控制器中

            /// <summary>
            /// 上传图片
            /// </summary>
            /// <param name="userId"></param>
            /// <param name="IsService"></param>
            /// <returns></returns>
            [HttpPost]
            public async Task<JsonResult> UserFeedbackProblemOfPicture(int userId, bool IsService)
            {
                try
                {
                    var file = Request.Form.Files[0];
                    var pictureurl = await _problemFeedbackService.UserFeedbackProblemOfPictureAsync(userId, file, IsService);
                    if (pictureurl == null)
                    {
                        return Json(new Str.Result<string>(Str.StatusCode.MissingParam));
                    }
                    return Json(new Str.Result<string>(Str.StatusCode.Success, pictureurl));
                }
                catch (Exception ex)
                {
                    return Json(new Str.Result<string>(Str.StatusCode.MissingParam));
                }
            }

    service中的方法

            /// <summary>
            /// 用户反馈问题(图片)
            /// </summary>
            /// <param name="userId"></param>
            /// <param name="file"></param>
            /// <param name="IsService"></param>
            /// <returns></returns>
            public async Task<string> UserFeedbackProblemOfPictureAsync(int userId, IFormFile file, bool IsService)
            {
                var datePath = DateTime.Now.ToString("yyyyMMdd");
                var fileName = DESEncrypt.CryptMd5String(Guid.NewGuid().ToString()) + System.IO.Path.GetExtension(file.FileName);
                string savePath = String.Format(FileConfigValue.UploadFolder, FileConfigValue.FuncPath, datePath);
                string filePath = string.Format(FileConfigValue.UploadFolder, FileConfigValue.FuncPath, datePath) + fileName;
                string url = string.Format(FileConfigValue.WebPerfix, FileConfigValue.FuncPath, datePath) + fileName;
                var cndImgUrl = url;
                if (file != null)
                {
                    if (!Directory.Exists(savePath))
                    {
                        Directory.CreateDirectory(savePath);
                    }
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
              //其他逻辑处理
                   
                }
                return null;
            }
  • 相关阅读:
    【转】js 获取浏览器高度和宽度值(多浏览器)
    Css相册
    微信公众号开发笔记2-自定义菜单
    微信公众号开发笔记1-获取Access Token
    【转】CSS选择器笔记
    【转】CSS浮动(float,clear)通俗讲解
    高云的jQuery源码分析笔记
    经典闭包例子详解
    执行控制——节流模式
    图片上下左右的无缝滚动的实现
  • 原文地址:https://www.cnblogs.com/carlpeng/p/13269053.html
Copyright © 2011-2022 走看看