😎去掉文件上传指定路径参数及验证文件名合法性
This commit is contained in:
parent
1c858b530b
commit
7e1fee09c3
@ -553,6 +553,12 @@ public enum ErrorCodeEnum
|
|||||||
[ErrorCodeItemMetadata("文件已存在")]
|
[ErrorCodeItemMetadata("文件已存在")]
|
||||||
D8004,
|
D8004,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 无效的文件名
|
||||||
|
/// </summary>
|
||||||
|
[ErrorCodeItemMetadata("无效的文件名")]
|
||||||
|
D8005,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 已存在同名或同编码配置参数
|
/// 已存在同名或同编码配置参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -16,14 +16,10 @@ public class PageFileInput : BasePageInput
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string FileName { get; set; }
|
public string FileName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 文件路径
|
|
||||||
/// </summary>
|
|
||||||
public string FilePath { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件后缀
|
/// 文件后缀
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <example></example>
|
||||||
public string? Suffix { get; set; }
|
public string? Suffix { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -59,11 +55,13 @@ public class UploadFileInput
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件类别
|
/// 文件类别
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <example></example>
|
||||||
public string FileType { get; set; }
|
public string FileType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件别名
|
/// 文件别名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <example></example>
|
||||||
public string FileAlias { get; set; }
|
public string FileAlias { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -71,19 +69,10 @@ public class UploadFileInput
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsPublic { get; set; } = false;
|
public bool IsPublic { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 文件路径
|
|
||||||
/// </summary>
|
|
||||||
public string Path { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 文件保存路径
|
|
||||||
/// </summary>
|
|
||||||
public string SavePath { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 允许格式:.jpeg.jpg.png.bmp.gif.tif
|
/// 允许格式:.jpeg.jpg.png.bmp.gif.tif
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <example></example>
|
||||||
public string AllowSuffix { get; set; }
|
public string AllowSuffix { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,25 +94,23 @@ public class UploadFileFromBase64Input
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件类型( "image/jpeg",)
|
/// 文件类型( "image/jpeg",)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <example></example>
|
||||||
public string ContentType { get; set; }
|
public string ContentType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件类别
|
/// 文件类别
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <example></example>
|
||||||
public string FileType { get; set; }
|
public string FileType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件别名
|
/// 文件别名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <example></example>
|
||||||
public string FileAlias { get; set; }
|
public string FileAlias { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否公开
|
/// 是否公开
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsPublic { get; set; } = false;
|
public bool IsPublic { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 保存路径
|
|
||||||
/// </summary>
|
|
||||||
public string Path { get; set; }
|
|
||||||
}
|
}
|
||||||
@ -62,7 +62,6 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
// 合并公开和私有并分页
|
// 合并公开和私有并分页
|
||||||
return await _sysFileRep.Context.UnionAll(publicList, privateList)
|
return await _sysFileRep.Context.UnionAll(publicList, privateList)
|
||||||
.WhereIF(!string.IsNullOrWhiteSpace(input.FileName), u => u.FileName.Contains(input.FileName.Trim()))
|
.WhereIF(!string.IsNullOrWhiteSpace(input.FileName), u => u.FileName.Contains(input.FileName.Trim()))
|
||||||
.WhereIF(!string.IsNullOrWhiteSpace(input.FilePath), u => u.FilePath.Contains(input.FilePath.Trim()))
|
|
||||||
.WhereIF(!string.IsNullOrWhiteSpace(input.StartTime.ToString()) && !string.IsNullOrWhiteSpace(input.EndTime.ToString()),
|
.WhereIF(!string.IsNullOrWhiteSpace(input.StartTime.ToString()) && !string.IsNullOrWhiteSpace(input.EndTime.ToString()),
|
||||||
u => u.CreateTime >= input.StartTime && u.CreateTime <= input.EndTime)
|
u => u.CreateTime >= input.StartTime && u.CreateTime <= input.EndTime)
|
||||||
.OrderBy(u => u.CreateTime, OrderByType.Desc)
|
.OrderBy(u => u.CreateTime, OrderByType.Desc)
|
||||||
@ -239,7 +238,9 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
[DisplayName("上传文件")]
|
[DisplayName("上传文件")]
|
||||||
public async Task<SysFile> UploadFile([FromForm] UploadFileInput input)
|
public async Task<SysFile> UploadFile([FromForm] UploadFileInput input)
|
||||||
{
|
{
|
||||||
if (input.File == null) throw Oops.Oh(ErrorCodeEnum.D8000);
|
if (input.File == null || input.File.Length <= 0) throw Oops.Oh(ErrorCodeEnum.D8000);
|
||||||
|
|
||||||
|
if (input.File.FileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) throw Oops.Oh(ErrorCodeEnum.D8005);
|
||||||
|
|
||||||
// 判断是否重复上传的文件
|
// 判断是否重复上传的文件
|
||||||
var sizeKb = input.File.Length / 1024; // 大小KB
|
var sizeKb = input.File.Length / 1024; // 大小KB
|
||||||
@ -281,8 +282,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
//if (!VerifyFileExtensionName.IsSameType(file.OpenReadStream(), suffix)) throw Oops.Oh(ErrorCodeEnum.D8001);
|
//if (!VerifyFileExtensionName.IsSameType(file.OpenReadStream(), suffix)) throw Oops.Oh(ErrorCodeEnum.D8001);
|
||||||
|
|
||||||
// 文件存储位置
|
// 文件存储位置
|
||||||
var path = string.IsNullOrWhiteSpace(input.SavePath) ? _uploadOptions.Path : input.SavePath;
|
var path = _uploadOptions.Path.ParseToDateTimeForRep();
|
||||||
path = path.ParseToDateTimeForRep();
|
|
||||||
|
|
||||||
var newFile = input.Adapt<SysFile>();
|
var newFile = input.Adapt<SysFile>();
|
||||||
newFile.Id = YitIdHelper.NextId();
|
newFile.Id = YitIdHelper.NextId();
|
||||||
@ -309,7 +309,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
[DisplayName("上传头像")]
|
[DisplayName("上传头像")]
|
||||||
public async Task<SysFile> UploadAvatar([Required] IFormFile file)
|
public async Task<SysFile> UploadAvatar([Required] IFormFile file)
|
||||||
{
|
{
|
||||||
var sysFile = await UploadFile(new UploadFileInput { File = file, AllowSuffix = _imageType, SavePath = "upload/avatar" });
|
var sysFile = await UploadFile(new UploadFileInput { File = file, AllowSuffix = _imageType });
|
||||||
|
|
||||||
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
||||||
var user = await sysUserRep.GetByIdAsync(_userManager.UserId);
|
var user = await sysUserRep.GetByIdAsync(_userManager.UserId);
|
||||||
@ -331,7 +331,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
[DisplayName("上传电子签名")]
|
[DisplayName("上传电子签名")]
|
||||||
public async Task<SysFile> UploadSignature([Required] IFormFile file)
|
public async Task<SysFile> UploadSignature([Required] IFormFile file)
|
||||||
{
|
{
|
||||||
var sysFile = await UploadFile(new UploadFileInput { File = file, AllowSuffix = _imageType, SavePath = "upload/signature" });
|
var sysFile = await UploadFile(new UploadFileInput { File = file, AllowSuffix = _imageType });
|
||||||
|
|
||||||
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
||||||
var user = await sysUserRep.GetByIdAsync(_userManager.UserId);
|
var user = await sysUserRep.GetByIdAsync(_userManager.UserId);
|
||||||
|
|||||||
@ -721,7 +721,7 @@ public class SysTenantService : IDynamicApiController, ITransient
|
|||||||
Directory.CreateDirectory(absoluteDirPath);
|
Directory.CreateDirectory(absoluteDirPath);
|
||||||
|
|
||||||
// 保存轮播图文件
|
// 保存轮播图文件
|
||||||
var sysFile = await _sysFileService.UploadFile(new UploadFileInput { File = file, FileType = "Carousel", SavePath = path });
|
var sysFile = await _sysFileService.UploadFile(new UploadFileInput { File = file, FileType = "Carousel" });
|
||||||
|
|
||||||
//// 保存轮播图配置
|
//// 保存轮播图配置
|
||||||
//sysFile.BelongId = tenant.Id;
|
//sysFile.BelongId = tenant.Id;
|
||||||
|
|||||||
@ -149,7 +149,7 @@ public class SysWxOpenService : IDynamicApiController, ITransient
|
|||||||
if (wxUser == null)
|
if (wxUser == null)
|
||||||
throw Oops.Oh("未找到用户上传失败");
|
throw Oops.Oh("未找到用户上传失败");
|
||||||
|
|
||||||
var res = await _sysFileService.UploadFile(new UploadFileInput { File = input.File, FileType = input.FileType, Path = input.Path });
|
var res = await _sysFileService.UploadFile(new UploadFileInput { File = input.File, FileType = input.FileType });
|
||||||
wxUser.Avatar = res.Url;
|
wxUser.Avatar = res.Url;
|
||||||
await _sysOAuthUserRep.AsUpdateable(wxUser).IgnoreColumns(true).ExecuteCommandAsync();
|
await _sysOAuthUserRep.AsUpdateable(wxUser).IgnoreColumns(true).ExecuteCommandAsync();
|
||||||
|
|
||||||
|
|||||||
@ -573,13 +573,11 @@ export const SysFileApiAxiosParamCreator = function (configuration?: Configurati
|
|||||||
* @param {string} [fileType]
|
* @param {string} [fileType]
|
||||||
* @param {string} [fileAlias]
|
* @param {string} [fileAlias]
|
||||||
* @param {boolean} [isPublic]
|
* @param {boolean} [isPublic]
|
||||||
* @param {string} [path]
|
|
||||||
* @param {string} [savePath]
|
|
||||||
* @param {string} [allowSuffix]
|
* @param {string} [allowSuffix]
|
||||||
* @param {*} [options] Override http request option.
|
* @param {*} [options] Override http request option.
|
||||||
* @throws {RequiredError}
|
* @throws {RequiredError}
|
||||||
*/
|
*/
|
||||||
apiSysFileUploadFilePostForm: async (file?: Blob, fileType?: string, fileAlias?: string, isPublic?: boolean, path?: string, savePath?: string, allowSuffix?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
apiSysFileUploadFilePostForm: async (file?: Blob, fileType?: string, fileAlias?: string, isPublic?: boolean, allowSuffix?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||||
const localVarPath = `/api/sysFile/uploadFile`;
|
const localVarPath = `/api/sysFile/uploadFile`;
|
||||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||||
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
|
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
|
||||||
@ -618,14 +616,6 @@ export const SysFileApiAxiosParamCreator = function (configuration?: Configurati
|
|||||||
localVarFormParams.append('IsPublic', isPublic as any);
|
localVarFormParams.append('IsPublic', isPublic as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path !== undefined) {
|
|
||||||
localVarFormParams.append('Path', path as any);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (savePath !== undefined) {
|
|
||||||
localVarFormParams.append('SavePath', savePath as any);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (allowSuffix !== undefined) {
|
if (allowSuffix !== undefined) {
|
||||||
localVarFormParams.append('AllowSuffix', allowSuffix as any);
|
localVarFormParams.append('AllowSuffix', allowSuffix as any);
|
||||||
}
|
}
|
||||||
@ -923,14 +913,12 @@ export const SysFileApiFp = function(configuration?: Configuration) {
|
|||||||
* @param {string} [fileType]
|
* @param {string} [fileType]
|
||||||
* @param {string} [fileAlias]
|
* @param {string} [fileAlias]
|
||||||
* @param {boolean} [isPublic]
|
* @param {boolean} [isPublic]
|
||||||
* @param {string} [path]
|
|
||||||
* @param {string} [savePath]
|
|
||||||
* @param {string} [allowSuffix]
|
* @param {string} [allowSuffix]
|
||||||
* @param {*} [options] Override http request option.
|
* @param {*} [options] Override http request option.
|
||||||
* @throws {RequiredError}
|
* @throws {RequiredError}
|
||||||
*/
|
*/
|
||||||
async apiSysFileUploadFilePostForm(file?: Blob, fileType?: string, fileAlias?: string, isPublic?: boolean, path?: string, savePath?: string, allowSuffix?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<AdminNETResultSysFile>>> {
|
async apiSysFileUploadFilePostForm(file?: Blob, fileType?: string, fileAlias?: string, isPublic?: boolean, allowSuffix?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<AdminNETResultSysFile>>> {
|
||||||
const localVarAxiosArgs = await SysFileApiAxiosParamCreator(configuration).apiSysFileUploadFilePostForm(file, fileType, fileAlias, isPublic, path, savePath, allowSuffix, options);
|
const localVarAxiosArgs = await SysFileApiAxiosParamCreator(configuration).apiSysFileUploadFilePostForm(file, fileType, fileAlias, isPublic, allowSuffix, options);
|
||||||
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
|
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
|
||||||
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
|
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
|
||||||
return axios.request(axiosRequestArgs);
|
return axios.request(axiosRequestArgs);
|
||||||
@ -1090,14 +1078,12 @@ export const SysFileApiFactory = function (configuration?: Configuration, basePa
|
|||||||
* @param {string} [fileType]
|
* @param {string} [fileType]
|
||||||
* @param {string} [fileAlias]
|
* @param {string} [fileAlias]
|
||||||
* @param {boolean} [isPublic]
|
* @param {boolean} [isPublic]
|
||||||
* @param {string} [path]
|
|
||||||
* @param {string} [savePath]
|
|
||||||
* @param {string} [allowSuffix]
|
* @param {string} [allowSuffix]
|
||||||
* @param {*} [options] Override http request option.
|
* @param {*} [options] Override http request option.
|
||||||
* @throws {RequiredError}
|
* @throws {RequiredError}
|
||||||
*/
|
*/
|
||||||
async apiSysFileUploadFilePostForm(file?: Blob, fileType?: string, fileAlias?: string, isPublic?: boolean, path?: string, savePath?: string, allowSuffix?: string, options?: AxiosRequestConfig): Promise<AxiosResponse<AdminNETResultSysFile>> {
|
async apiSysFileUploadFilePostForm(file?: Blob, fileType?: string, fileAlias?: string, isPublic?: boolean, allowSuffix?: string, options?: AxiosRequestConfig): Promise<AxiosResponse<AdminNETResultSysFile>> {
|
||||||
return SysFileApiFp(configuration).apiSysFileUploadFilePostForm(file, fileType, fileAlias, isPublic, path, savePath, allowSuffix, options).then((request) => request(axios, basePath));
|
return SysFileApiFp(configuration).apiSysFileUploadFilePostForm(file, fileType, fileAlias, isPublic, allowSuffix, options).then((request) => request(axios, basePath));
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -1257,15 +1243,13 @@ export class SysFileApi extends BaseAPI {
|
|||||||
* @param {string} [fileType]
|
* @param {string} [fileType]
|
||||||
* @param {string} [fileAlias]
|
* @param {string} [fileAlias]
|
||||||
* @param {boolean} [isPublic]
|
* @param {boolean} [isPublic]
|
||||||
* @param {string} [path]
|
|
||||||
* @param {string} [savePath]
|
|
||||||
* @param {string} [allowSuffix]
|
* @param {string} [allowSuffix]
|
||||||
* @param {*} [options] Override http request option.
|
* @param {*} [options] Override http request option.
|
||||||
* @throws {RequiredError}
|
* @throws {RequiredError}
|
||||||
* @memberof SysFileApi
|
* @memberof SysFileApi
|
||||||
*/
|
*/
|
||||||
public async apiSysFileUploadFilePostForm(file?: Blob, fileType?: string, fileAlias?: string, isPublic?: boolean, path?: string, savePath?: string, allowSuffix?: string, options?: AxiosRequestConfig) : Promise<AxiosResponse<AdminNETResultSysFile>> {
|
public async apiSysFileUploadFilePostForm(file?: Blob, fileType?: string, fileAlias?: string, isPublic?: boolean, allowSuffix?: string, options?: AxiosRequestConfig) : Promise<AxiosResponse<AdminNETResultSysFile>> {
|
||||||
return SysFileApiFp(this.configuration).apiSysFileUploadFilePostForm(file, fileType, fileAlias, isPublic, path, savePath, allowSuffix, options).then((request) => request(this.axios, this.basePath));
|
return SysFileApiFp(this.configuration).apiSysFileUploadFilePostForm(file, fileType, fileAlias, isPublic, allowSuffix, options).then((request) => request(this.axios, this.basePath));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -90,14 +90,6 @@ export interface PageFileInput {
|
|||||||
*/
|
*/
|
||||||
fileName?: string | null;
|
fileName?: string | null;
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件路径
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof PageFileInput
|
|
||||||
*/
|
|
||||||
filePath?: string | null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件后缀
|
* 文件后缀
|
||||||
*
|
*
|
||||||
|
|||||||
@ -52,22 +52,6 @@ export interface SysFileUploadFileBody {
|
|||||||
*/
|
*/
|
||||||
isPublic?: boolean;
|
isPublic?: boolean;
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件路径
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof SysFileUploadFileBody
|
|
||||||
*/
|
|
||||||
path?: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件保存路径
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof SysFileUploadFileBody
|
|
||||||
*/
|
|
||||||
savePath?: string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 允许格式:.jpeg.jpg.png.bmp.gif.tif
|
* 允许格式:.jpeg.jpg.png.bmp.gif.tif
|
||||||
*
|
*
|
||||||
|
|||||||
@ -67,12 +67,4 @@ export interface UploadFileFromBase64Input {
|
|||||||
* @memberof UploadFileFromBase64Input
|
* @memberof UploadFileFromBase64Input
|
||||||
*/
|
*/
|
||||||
isPublic?: boolean;
|
isPublic?: boolean;
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存路径
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof UploadFileFromBase64Input
|
|
||||||
*/
|
|
||||||
path?: string | null;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user