文件上传存储到阿里云新增自定义文件名
This commit is contained in:
parent
b8e4cd2421
commit
4fefb4282d
@ -175,7 +175,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + (MaxContentLength / 1024).ToString() + " MB");
|
||||
}
|
||||
|
||||
(bool, string, string) result = SysFileService.SaveFile(fileDir, formFile);
|
||||
(bool, string, string) result = SysFileService.SaveFile(fileDir, formFile, fileName);
|
||||
long fileId = SysFileService.InsertFile(new SysFile()
|
||||
{
|
||||
AccessUrl = result.Item2,
|
||||
|
||||
@ -43,6 +43,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
predicate = predicate.AndIF(parm.BeginCreate_time != null, it => it.Create_time >= parm.BeginCreate_time);
|
||||
predicate = predicate.AndIF(parm.EndCreate_time != null, it => it.Create_time <= parm.EndCreate_time);
|
||||
predicate = predicate.AndIF(parm.StoreType != null, m => m.StoreType == parm.StoreType);
|
||||
predicate = predicate.AndIF(parm.FileId != null, m => m.Id == parm.FileId);
|
||||
|
||||
//搜索条件查询语法参考Sqlsugar
|
||||
var response = _SysFileService.GetPages(predicate.ToExpression(), parm);
|
||||
@ -59,7 +60,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
public IActionResult GetSysFile(int Id)
|
||||
{
|
||||
var response = _SysFileService.GetFirst(x => x.Id == Id);
|
||||
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
|
||||
@ -25,5 +25,6 @@ namespace ZR.Model.System.Dto
|
||||
public DateTime? BeginCreate_time { get; set; }
|
||||
public DateTime? EndCreate_time { get; set; }
|
||||
public int? StoreType { get; set; }
|
||||
public int? FileId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ namespace ZR.Service.System.IService
|
||||
/// <param name="formFile"></param>
|
||||
/// <returns>结果、地址、文件名</returns>
|
||||
(bool, string, string) SaveFile(string picdir, IFormFile formFile);
|
||||
|
||||
(bool, string, string) SaveFile(string picdir, IFormFile formFile, string customFileName);
|
||||
/// <summary>
|
||||
/// 按时间来创建文件夹
|
||||
/// </summary>
|
||||
|
||||
@ -10,6 +10,7 @@ using System.Security.Cryptography;
|
||||
using System.Net;
|
||||
using ZR.Model.System;
|
||||
using ZR.Repository.System;
|
||||
using Infrastructure.Extensions;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
@ -35,9 +36,13 @@ namespace ZR.Service.System
|
||||
/// <returns></returns>
|
||||
public (bool, string, string) SaveFile(string picdir, IFormFile formFile)
|
||||
{
|
||||
// eg: idcard/2020/08/18
|
||||
return SaveFile(picdir, formFile, "");
|
||||
}
|
||||
public (bool, string, string) SaveFile(string picdir, IFormFile formFile, string customFileName)
|
||||
{
|
||||
// eg: uploads/2020/08/18
|
||||
string dir = GetdirPath(picdir.ToString());
|
||||
string tempName = HashFileName();
|
||||
string tempName = customFileName.IsEmpty() ? HashFileName() : customFileName;
|
||||
string fileExt = Path.GetExtension(formFile.FileName);
|
||||
string fileName = $"{tempName}{fileExt}";
|
||||
string webUrl = $"{domainUrl}/{dir}/{fileName}";
|
||||
@ -46,7 +51,6 @@ namespace ZR.Service.System
|
||||
|
||||
return (statusCode == HttpStatusCode.OK, webUrl, fileName);
|
||||
}
|
||||
|
||||
public string GetdirPath(string path = "")
|
||||
{
|
||||
DateTime date = DateTime.Now;
|
||||
|
||||
@ -162,7 +162,7 @@ export default {
|
||||
}
|
||||
this.msgSuccess("上传成功");
|
||||
this.fileList.push({ name: res.data.fileName, url: res.data.url, path: res.data.path });
|
||||
this.$emit("input", this.column, this.listToString(this.fileList));
|
||||
this.$emit("input", this.column, this.listToString(this.fileList), res.data);
|
||||
},
|
||||
// 上传进度
|
||||
uploadProcess(event, file, fileList) {
|
||||
|
||||
@ -2,6 +2,9 @@
|
||||
<div class="app-container">
|
||||
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
||||
<el-form :model="queryParams" label-position="left" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch" @submit.native.prevent>
|
||||
<el-form-item label="文件id" prop="fileId">
|
||||
<el-input v-model="queryParams.fileId" placeholder="请输入文件id" clearable size="small" />
|
||||
</el-form-item>
|
||||
<el-form-item label="上传时间">
|
||||
<el-date-picker v-model="dateRangeCreate_time" size="small" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
|
||||
start-placeholder="开始日期" end-placeholder="结束日期" placeholder="请选择上传时间"></el-date-picker>
|
||||
@ -11,11 +14,10 @@
|
||||
<el-option v-for="item in storeTypeOptions" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-row class="mb8" style="text-align:center">
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<!-- 工具区域 -->
|
||||
<el-row :gutter="10" class="mb8">
|
||||
@ -168,6 +170,7 @@ export default {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
storeType: 1,
|
||||
fileId: undefined,
|
||||
},
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
@ -257,12 +260,12 @@ export default {
|
||||
reset() {
|
||||
this.form = {
|
||||
fileName: "",
|
||||
fileUrl: undefined,
|
||||
fileUrl: "",
|
||||
storePath: "uploads",
|
||||
fileSize: undefined,
|
||||
fileExt: undefined,
|
||||
fileSize: 0,
|
||||
fileExt: "",
|
||||
storeType: 1,
|
||||
accessUrl: undefined,
|
||||
accessUrl: "",
|
||||
};
|
||||
this.resetForm("form");
|
||||
},
|
||||
@ -317,9 +320,9 @@ export default {
|
||||
});
|
||||
},
|
||||
//上传成功方法
|
||||
handleUploadSuccess(columnName, filelist) {
|
||||
handleUploadSuccess(columnName, filelist, data) {
|
||||
this.form[columnName] = filelist;
|
||||
|
||||
this.queryParams.fileId = data.fileId;
|
||||
this.open = false;
|
||||
this.getList();
|
||||
},
|
||||
@ -328,7 +331,7 @@ export default {
|
||||
return this.selectDictLabel(this.storeTypeOptions, row.storeType);
|
||||
},
|
||||
handleSelectStore(val) {
|
||||
this.queryParams.storeType = val;
|
||||
this.queryParams.storeType = val;
|
||||
if (val == 1) {
|
||||
this.uploadUrl = "/common/uploadFile";
|
||||
} else if (val == 2) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user