mirror of
https://github.com/anjoy8/Blog.Core.git
synced 2024-09-20 23:48:27 +08:00
feat: change file upload api
This commit is contained in:
parent
48a4adcd37
commit
ddb326763b
|
@ -54,11 +54,11 @@ namespace Blog.Core.Controllers
|
||||||
public async Task<MessageModel<string>> InsertPicture([FromForm]UploadFileDto dto)
|
public async Task<MessageModel<string>> InsertPicture([FromForm]UploadFileDto dto)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (dto.Files == null || !dto.Files.Any()) return Failed("请选择上传的文件。");
|
if (dto.file == null || !dto.file.Any()) return Failed("请选择上传的文件。");
|
||||||
//格式限制
|
//格式限制
|
||||||
var allowType = new string[] { "image/jpg", "image/png", "image/jpeg" };
|
var allowType = new string[] { "image/jpg", "image/png", "image/jpeg" };
|
||||||
|
|
||||||
var allowedFile = dto.Files.Where(c => allowType.Contains(c.ContentType));
|
var allowedFile = dto.file.Where(c => allowType.Contains(c.ContentType));
|
||||||
if (!allowedFile.Any()) return Failed("图片格式错误");
|
if (!allowedFile.Any()) return Failed("图片格式错误");
|
||||||
if (allowedFile.Sum(c => c.Length) > 1024 * 1024 * 4) return Failed("图片过大");
|
if (allowedFile.Sum(c => c.Length) > 1024 * 1024 * 4) return Failed("图片过大");
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ namespace Blog.Core.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var excludeFiles = dto.Files.Except(allowedFile);
|
var excludeFiles = dto.file.Except(allowedFile);
|
||||||
|
|
||||||
if (excludeFiles.Any())
|
if (excludeFiles.Any())
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Blog.Core.Model.ViewModels
|
namespace Blog.Core.Model.ViewModels
|
||||||
{
|
{
|
||||||
|
@ -12,7 +7,7 @@ namespace Blog.Core.Model.ViewModels
|
||||||
{
|
{
|
||||||
//多文件
|
//多文件
|
||||||
[Required]
|
[Required]
|
||||||
public IFormFileCollection Files { get; set; }
|
public IFormFileCollection file { get; set; }
|
||||||
|
|
||||||
//单文件
|
//单文件
|
||||||
//public IFormFile File { get; set; }
|
//public IFormFile File { get; set; }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user