Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
Laisi_AutoMES2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiawei.su
Laisi_AutoMES2
Commits
65a889f2
Commit
65a889f2
authored
Jan 21, 2021
by
xin.yang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some update
parent
0b92b558
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
DownloadController.cs
Server/Apis/Siger.ApiConfig/Controller/DownloadController.cs
+47
-0
No files found.
Server/Apis/Siger.ApiConfig/Controller/DownloadController.cs
View file @
65a889f2
...
...
@@ -312,5 +312,51 @@ namespace Siger.ApiConfig.Controller
return
new
ObjectResult
(
new
{
content
=
FileUtility
.
GetText
(
truePath
)
});
}
/// <summary>
/// 下载文件
/// </summary>
/// <returns></returns>
[
HttpGet
]
[
NoResultFilter
]
public
IActionResult
DownloadFileByUrl
(
string
url
,
string
name
)
{
if
(
string
.
IsNullOrWhiteSpace
(
url
))
{
return
new
NoContentResult
();
}
var
fileSetting
=
Config
<
FileSettings
>.
Get
();
if
(
fileSetting
==
null
)
{
return
new
NoContentResult
();
}
var
rootDir
=
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
fileSetting
.
FileSetting
.
PhysicalFolder
);
if
(!
Directory
.
Exists
(
rootDir
))
{
return
new
NoContentResult
();
}
var
path
=
rootDir
+
url
;
if
(!
System
.
IO
.
File
.
Exists
(
path
))
{
return
new
NoContentResult
();
}
try
{
var
stream
=
new
FileStream
(
path
,
FileMode
.
Open
,
FileAccess
.
ReadWrite
,
FileShare
.
ReadWrite
);
var
response
=
new
HttpResponseMessage
(
HttpStatusCode
.
OK
)
{
Content
=
new
StreamContent
(
stream
)
};
response
.
Content
.
Headers
.
ContentType
=
new
MediaTypeHeaderValue
(
"application/octet-stream"
);
response
.
Content
.
Headers
.
ContentDisposition
=
new
ContentDispositionHeaderValue
(
"attachment"
)
{
FileName
=
string
.
IsNullOrWhiteSpace
(
name
)
?
url
.
Substring
(
url
.
LastIndexOf
(
'.'
))
:
name
};
return
File
(
stream
,
"application/octet-stream"
);
}
catch
{
throw
new
BadRequestException
(
CommonEnum
.
Fail
);
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment