Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 0e4a9f29
authored
May 20, 2021
by
水库浪子
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
文件下载相关代码提交;
1 parent
98003001
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
10 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/common/CommonController.java
linkwe-framework/src/main/java/com/linkwechat/framework/web/service/FileService.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/common/CommonController.java
View file @
0e4a9f2
...
@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
...
@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -33,9 +34,6 @@ public class CommonController {
...
@@ -33,9 +34,6 @@ public class CommonController {
@Autowired
@Autowired
private
ServerConfig
serverConfig
;
private
ServerConfig
serverConfig
;
@Autowired
private
CosConfig
cosConfig
;
@Autowired
@Autowired
private
FileService
fileService
;
private
FileService
fileService
;
...
@@ -122,12 +120,8 @@ public class CommonController {
...
@@ -122,12 +120,8 @@ public class CommonController {
@PostMapping
(
"/common/uploadFile2Cos"
)
@PostMapping
(
"/common/uploadFile2Cos"
)
public
AjaxResult
uploadFile2Cos
(
MultipartFile
file
)
throws
Exception
{
public
AjaxResult
uploadFile2Cos
(
MultipartFile
file
)
throws
Exception
{
try
{
try
{
SysFile
sysFile
SysFile
sysFile
=
fileService
.
upload
(
file
);
=
fileService
.
upload
(
file
);
// String fileName = FileUploadUtils.upload2Cos(file, cosConfig);
AjaxResult
ajax
=
AjaxResult
.
success
();
AjaxResult
ajax
=
AjaxResult
.
success
();
ajax
.
put
(
"fileName"
,
sysFile
.
getFileName
());
ajax
.
put
(
"fileName"
,
sysFile
.
getFileName
());
ajax
.
put
(
"url"
,
sysFile
.
getImgUrlPrefix
()+
sysFile
.
getFileName
());
ajax
.
put
(
"url"
,
sysFile
.
getImgUrlPrefix
()+
sysFile
.
getFileName
());
...
@@ -138,8 +132,15 @@ public class CommonController {
...
@@ -138,8 +132,15 @@ public class CommonController {
}
}
// public String url(String fileName){
/**
// return "https://link-wechat-1251309172.cos.ap-nanjing.myqcloud.com/"+fileName;
* 本地图片下载
// }
*/
@GetMapping
(
"/findFile"
)
public
void
findFile
(
HttpServletResponse
response
,
String
fileName
){
fileService
.
findFile
(
fileName
,
response
);
}
}
}
linkwe-framework/src/main/java/com/linkwechat/framework/web/service/FileService.java
View file @
0e4a9f2
...
@@ -9,8 +9,11 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -9,8 +9,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
/**
/**
...
@@ -56,4 +59,40 @@ public class FileService {
...
@@ -56,4 +59,40 @@ public class FileService {
}
}
public
void
findFile
(
String
fileName
,
HttpServletResponse
rp
){
String
fileDownUrl
=
""
;
// if(ruoYiConfig.getFile().isStartCosUpload()) {//开启云上传
// fileDownUrl= ruoYiConfig.getFile().getImgUrlPrefix();
// }else{
fileDownUrl
=
OsUtils
.
isWindows
()?
WINDOWSFILEPATH
+
fileName:
LINUXFILEPATH
+
fileName
;
// }
File
file
=
new
File
(
fileDownUrl
);
if
(
file
.
exists
())
{
FileInputStream
fis
=
null
;
OutputStream
os
=
null
;
try
{
fis
=
new
FileInputStream
(
file
);
os
=
rp
.
getOutputStream
();
int
count
=
0
;
byte
[]
buffer
=
new
byte
[
1024
*
8
];
while
((
count
=
fis
.
read
(
buffer
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
count
);
os
.
flush
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
fis
.
close
();
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment