.netcore接口文件上传时,有时需要限制上传文件大小,只需要在请求接口中加入RequestSizeLimit特性即可

  WebApiResult为自定义返回值

  

     /// <summary>
        /// 上传图片,限制大小为30M
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        [HttpPost("UploadImgFile30")]
        [RequestSizeLimit(30000000)]
        public WebApiResult UploadImgFile30(List<IFormFile> files)
        {
            try
            {
               
            }
            catch (Exception ex)
            {
                _logger.LogError($"上传图片:{JsonConvert.SerializeObject(ex)}");
                return new WebApiResult(ApiResultCode.Exception, ex.Message);

            }
        }

 

相关文章:

  • 2021-11-20
  • 2021-09-19
  • 2021-08-10
  • 2021-06-08
  • 2022-02-10
  • 2021-09-16
  • 2021-12-02
猜你喜欢
  • 2021-10-28
  • 2021-11-20
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
相关资源
相似解决方案