Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jyzb_local_platform
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Members
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
赵剑炜
jyzb_local_platform
Commits
6be37453
Commit
6be37453
authored
Oct 12, 2023
by
Seniorious
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
人员照片上传接口修复
parent
eb776ebd
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
40 行增加
和
56 行删除
+40
-56
APIs.csproj
WebApiNET6-master/APIs/APIs.csproj
+1
-1
BaseInfoController.cs
WebApiNET6-master/APIs/Controllers/BaseInfoController.cs
+34
-50
PictureReq.cs
WebApiNET6-master/APIs/Req/PictureReq.cs
+1
-1
Startup.cs
WebApiNET6-master/APIs/Startup.cs
+3
-1
Models.csproj
WebApiNET6-master/Models/Models.csproj
+1
-3
没有找到文件。
WebApiNET6-master/APIs/APIs.csproj
View file @
6be37453
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ImplicitUsings>enable</ImplicitUsings>
<ApplicationIcon>平台.ico</ApplicationIcon>
<ApplicationIcon>平台.ico</ApplicationIcon>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
...
...
WebApiNET6-master/APIs/Controllers/BaseInfoController.cs
View file @
6be37453
...
@@ -43,76 +43,61 @@ namespace APIs.Controllers
...
@@ -43,76 +43,61 @@ namespace APIs.Controllers
/// 人员照片上传
/// 人员照片上传
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
[
HttpGet
]
[
HttpPost
]
public
async
Task
<
ApiResult
>
UploadPicture
([
FromForm
]
PictureReq
req
)
public
async
Task
<
ApiResult
>
UploadPicture
([
FromBody
]
PictureReq
req
)
{
{
try
try
{
{
var
police
=
await
_policeService
.
QueryOne
(
p
=>
p
.
id
==
req
.
policeId
);
var
police
=
await
_policeService
.
QueryOne
(
p
=>
p
.
id
==
req
.
policeId
);
//警员不存在
//警员不存在
if
(
police
==
null
)
if
(
police
==
null
)
{
{
var
error
=
new
ApiResult
var
error
=
new
ApiResult
{
{
code
=
ResultCode
.
POLICE_ERROR
.
Code
,
code
=
ResultCode
.
POLICE_ERROR
.
Code
,
msg
=
ResultCode
.
POLICE_ERROR
.
Msg
,
msg
=
"警员不存在"
,
};
};
return
error
;
return
error
;
}
}
//存储图片
//存储图片
byte
[]
imageBytes
=
req
.
picture
;
var
ext
=
Path
.
GetExtension
(
req
.
picture
.
FileName
).
ToLower
()
;
string
filePath
=
""
;
using
(
MemoryStream
m
emoryStream
=
new
MemoryStream
(
imageBytes
))
using
(
MemoryStream
m
s
=
new
MemoryStream
(
))
{
{
using
(
Image
image
=
Image
.
FromStream
(
memoryStream
))
//拷贝文件到内存流
{
req
.
picture
.
CopyTo
(
ms
);
//图片格式
var
tmp
=
ms
.
GetBuffer
();
string
extension
=
string
.
Empty
;
var
fileType
=
tmp
[
0
].
ToString
()
+
tmp
[
1
].
ToString
();
ImageFormat
imageFormat
=
image
.
RawFormat
;
if
(
imageFormat
.
Equals
(
ImageFormat
.
Jpeg
))
var
path
=
"Pictures"
;
{
var
fileName
=
$"
{
req
.
policeId
}{
Path
.
GetExtension
(
req
.
picture
.
FileName
)}
"
;
extension
=
"jpg"
;
}
else
if
(
imageFormat
.
Equals
(
ImageFormat
.
Png
))
{
extension
=
"png"
;
}
else
if
(
imageFormat
.
Equals
(
ImageFormat
.
Gif
))
{
extension
=
"gif"
;
}
if
(
string
.
IsNullOrEmpty
(
extension
))
{
extension
=
"jpg"
;
}
filePath
=
$"Pictures/
{
req
.
policeId
}
.jpg"
;
// 图片保存路径
Directory
.
CreateDirectory
(
path
);
image
.
Save
(
filePath
);
var
filePath
=
Path
.
Combine
(
path
,
fileName
);
}
}
//更新警员照片地址
Image
.
FromStream
(
ms
).
Save
(
filePath
);
police
.
picUrl
=
filePath
;
police
.
updateTime
=
DateTime
.
Now
;
bool
rs
=
await
_policeService
.
Update
(
police
);
var
src
=
rs
?
new
ApiResult
//更新警员照片地址
{
police
.
picUrl
=
filePath
;
code
=
ResultCode
.
OPERATE_SUCCESS
.
Code
,
police
.
updateTime
=
DateTime
.
Now
;
msg
=
ResultCode
.
OPERATE_SUCCESS
.
Msg
,
bool
rs
=
await
_policeService
.
Update
(
police
);
data
=
""
}
:
new
ApiResult
{
code
=
ResultCode
.
OPERATE_FAILED
.
Code
,
msg
=
ResultCode
.
OPERATE_FAILED
.
Msg
,
data
=
""
};
return
src
;
var
src
=
rs
?
new
ApiResult
{
code
=
ResultCode
.
OPERATE_SUCCESS
.
Code
,
msg
=
ResultCode
.
OPERATE_SUCCESS
.
Msg
,
data
=
filePath
}
:
new
ApiResult
{
code
=
ResultCode
.
OPERATE_FAILED
.
Code
,
msg
=
"更新照片失败"
};
return
src
;
}
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
@@ -124,7 +109,6 @@ namespace APIs.Controllers
...
@@ -124,7 +109,6 @@ namespace APIs.Controllers
};
};
return
error
;
return
error
;
}
}
}
}
/// <summary>
/// <summary>
...
...
WebApiNET6-master/APIs/Req/PictureReq.cs
View file @
6be37453
...
@@ -3,6 +3,6 @@
...
@@ -3,6 +3,6 @@
public
class
PictureReq
public
class
PictureReq
{
{
public
string
policeId
{
get
;
set
;
}
public
string
policeId
{
get
;
set
;
}
public
byte
[]
picture
{
get
;
set
;
}
public
IFormFile
picture
{
get
;
set
;
}
}
}
}
}
WebApiNET6-master/APIs/Startup.cs
View file @
6be37453
...
@@ -17,6 +17,7 @@ using Repositories.Repository.UnitOfWork;
...
@@ -17,6 +17,7 @@ using Repositories.Repository.UnitOfWork;
using
Common.Utility.RabbitMQ
;
using
Common.Utility.RabbitMQ
;
using
Common.Global
;
using
Common.Global
;
using
System.Xml.Linq
;
using
System.Xml.Linq
;
using
Microsoft.AspNetCore.Mvc
;
namespace
APIs
namespace
APIs
{
{
...
@@ -40,10 +41,11 @@ namespace APIs
...
@@ -40,10 +41,11 @@ namespace APIs
services
.
AddControllers
()
services
.
AddControllers
()
.
AddNewtonsoftJson
(
options
=>
.
AddNewtonsoftJson
(
options
=>
{
{
options
.
SerializerSettings
.
ReferenceLoopHandling
=
Newtonsoft
.
Json
.
ReferenceLoopHandling
.
Ignore
;
options
.
SerializerSettings
.
ReferenceLoopHandling
=
Newtonsoft
.
Json
.
ReferenceLoopHandling
.
Ignore
;
options
.
SerializerSettings
.
DateFormatString
=
"yyyy-MM-dd HH:mm:ss"
;
options
.
SerializerSettings
.
DateFormatString
=
"yyyy-MM-dd HH:mm:ss"
;
});
});
//services.AddControllers(options => { options.Filters.Add(new ConsumesAttribute("multipart/form-data")); });
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
services
.
AddEndpointsApiExplorer
();
services
.
AddEndpointsApiExplorer
();
services
.
AddAutoMapper
(
typeof
(
MapperProfile
));
services
.
AddAutoMapper
(
typeof
(
MapperProfile
));
...
...
WebApiNET6-master/Models/Models.csproj
View file @
6be37453
...
@@ -7,9 +7,7 @@
...
@@ -7,9 +7,7 @@
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Reference Include="SqlSugar">
<PackageReference Include="SqlSugarCore" Version="5.1.4.106" />
<HintPath>..\..\..\..\..\Users\DELL\.nuget\packages\sqlsugarcore\5.1.4.106\lib\netstandard2.1\SqlSugar.dll</HintPath>
</Reference>
</ItemGroup>
</ItemGroup>
</Project>
</Project>
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论