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
191ff74f
Commit
191ff74f
authored
Jan 22, 2021
by
xin.yang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
074e22d5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
16 deletions
+10
-16
DownloadController.cs
Server/Apis/Siger.ApiConfig/Controller/DownloadController.cs
+10
-16
No files found.
Server/Apis/Siger.ApiConfig/Controller/DownloadController.cs
View file @
191ff74f
...
...
@@ -3,6 +3,7 @@ using System.IO;
using
System.Net
;
using
System.Net.Http
;
using
System.Net.Http.Headers
;
using
System.Web
;
using
Microsoft.AspNetCore.Mvc
;
using
Siger.ApiCommon.Filters
;
using
Siger.ApiCommon.Utilities
;
...
...
@@ -321,39 +322,32 @@ namespace Siger.ApiConfig.Controller
[
NoResultFilter
]
public
IActionResult
DownloadFileByUrl
(
string
url
,
string
name
)
{
if
(
string
.
IsNullOrWhiteSpace
(
url
))
if
(
!
string
.
IsNullOrEmpty
(
url
))
{
return
new
NoContentResult
();
}
var
fileSetting
=
Config
<
FileSettings
>.
Get
();
if
(
fileSetting
==
null
)
var
file_url
=
url
.
Split
(
"Files"
);
if
(
url
.
Length
==
2
)
{
return
new
NoContentResult
()
;
url
=
"Files"
+
file_url
[
1
]
;
}
var
rootDir
=
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
fileSetting
.
FileSetting
.
PhysicalFolder
);
if
(!
Directory
.
Exists
(
rootDir
))
{
return
new
NoContentResult
();
}
var
path
=
rootDir
+
url
;
var
path
=
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
url
).
Replace
(
"Files"
,
"TemporaryFiles"
);
if
(!
System
.
IO
.
File
.
Exists
(
path
))
{
return
new
NoContentResult
();
}
try
{
var
stream
=
new
FileStream
(
path
,
FileMode
.
Open
,
FileAccess
.
Read
Write
,
FileShare
.
ReadWrite
);
var
stream
=
new
FileStream
(
path
,
FileMode
.
Open
,
FileAccess
.
Read
,
FileShare
.
Read
);
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
FileName
=
name
};
return
File
(
stream
,
"application/octet-stream"
);
}
catch
catch
(
Exception
e
)
{
throw
new
BadRequestException
(
CommonEnum
.
Fail
);
}
...
...
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