Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-service-ruoyi
Project
Project
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
liuyan
cloud-service-ruoyi
Commits
5b1541a6
Commit
5b1541a6
authored
Apr 13, 2025
by
liuyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:增加配置文件
parent
89b2b532
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
3 deletions
+25
-3
~$admin.docx
doc/~$admin.docx
+0
-0
FileServiceImpl.java
...c/main/java/com/ruoyi/client/service/FileServiceImpl.java
+17
-3
application.yml
ruoyi-admin/src/main/resources/application.yml
+5
-0
server-config.yml
ruoyi-admin/src/main/resources/server-config.yml
+3
-0
No files found.
doc/~$admin.docx
deleted
100644 → 0
View file @
89b2b532
File deleted
ruoyi-admin/src/main/java/com/ruoyi/client/service/FileServiceImpl.java
View file @
5b1541a6
...
@@ -4,6 +4,7 @@ import com.google.protobuf.ByteString;
...
@@ -4,6 +4,7 @@ import com.google.protobuf.ByteString;
import
com.ruoyi.grpc.file.*
;
import
com.ruoyi.grpc.file.*
;
import
io.grpc.Status
;
import
io.grpc.Status
;
import
io.grpc.stub.StreamObserver
;
import
io.grpc.stub.StreamObserver
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
...
@@ -13,6 +14,9 @@ import java.io.IOException;
...
@@ -13,6 +14,9 @@ import java.io.IOException;
@Service
@Service
public
class
FileServiceImpl
extends
FileServiceGrpc
.
FileServiceImplBase
{
public
class
FileServiceImpl
extends
FileServiceGrpc
.
FileServiceImplBase
{
@Value
(
"${server.upload.base_path}"
)
String
uploadBasePath
;
@Override
@Override
public
StreamObserver
<
FileUploadRequest
>
uploadFile
(
StreamObserver
<
FileUploadResponse
>
responseObserver
)
{
public
StreamObserver
<
FileUploadRequest
>
uploadFile
(
StreamObserver
<
FileUploadResponse
>
responseObserver
)
{
return
new
StreamObserver
<
FileUploadRequest
>()
{
return
new
StreamObserver
<
FileUploadRequest
>()
{
...
@@ -25,13 +29,21 @@ public class FileServiceImpl extends FileServiceGrpc.FileServiceImplBase {
...
@@ -25,13 +29,21 @@ public class FileServiceImpl extends FileServiceGrpc.FileServiceImplBase {
try
{
try
{
if
(
request
.
hasFilename
())
{
if
(
request
.
hasFilename
())
{
filename
=
request
.
getFilename
();
filename
=
request
.
getFilename
();
fos
=
new
FileOutputStream
(
"E:\\server_file\\"
+
filename
);
// 创建文件对象
java
.
io
.
File
ioFile
=
new
java
.
io
.
File
(
uploadBasePath
+
filename
);
// 创建文件所在的目录
ioFile
.
getParentFile
().
mkdirs
();
// 创建文件,如果文件存在则覆盖
ioFile
.
createNewFile
();
fos
=
new
FileOutputStream
(
ioFile
);
}
else
{
}
else
{
byte
[]
chunk
=
request
.
getChunk
().
toByteArray
();
byte
[]
chunk
=
request
.
getChunk
().
toByteArray
();
totalSize
+=
chunk
.
length
;
totalSize
+=
chunk
.
length
;
fos
.
write
(
chunk
);
fos
.
write
(
chunk
);
}
}
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
e
.
printStackTrace
();
// 返回 INVALID_ARGUMENT 错误
// 返回 INVALID_ARGUMENT 错误
responseObserver
.
onError
(
Status
.
INVALID_ARGUMENT
responseObserver
.
onError
(
Status
.
INVALID_ARGUMENT
.
withDescription
(
"Upload failed:"
+
e
.
getMessage
())
.
withDescription
(
"Upload failed:"
+
e
.
getMessage
())
...
@@ -50,11 +62,12 @@ public class FileServiceImpl extends FileServiceGrpc.FileServiceImplBase {
...
@@ -50,11 +62,12 @@ public class FileServiceImpl extends FileServiceGrpc.FileServiceImplBase {
try
{
try
{
fos
.
close
();
fos
.
close
();
responseObserver
.
onNext
(
FileUploadResponse
.
newBuilder
()
responseObserver
.
onNext
(
FileUploadResponse
.
newBuilder
()
.
setStatus
(
"Success"
)
.
setStatus
(
Status
.
OK
.
toString
()
)
.
setSize
(
totalSize
)
.
setSize
(
totalSize
)
.
build
());
.
build
());
responseObserver
.
onCompleted
();
responseObserver
.
onCompleted
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
// 最终错误处理
// 最终错误处理
responseObserver
.
onError
(
Status
.
INTERNAL
responseObserver
.
onError
(
Status
.
INTERNAL
.
withDescription
(
"Finalization failed: "
+
e
.
getMessage
())
.
withDescription
(
"Finalization failed: "
+
e
.
getMessage
())
...
@@ -71,11 +84,12 @@ public class FileServiceImpl extends FileServiceGrpc.FileServiceImplBase {
...
@@ -71,11 +84,12 @@ public class FileServiceImpl extends FileServiceGrpc.FileServiceImplBase {
StreamObserver
<
FileDownloadResponse
>
responseObserver
)
{
StreamObserver
<
FileDownloadResponse
>
responseObserver
)
{
try
{
try
{
java
.
io
.
File
file
=
new
java
.
io
.
File
(
"server_files/"
+
request
.
getFilename
());
java
.
io
.
File
file
=
new
java
.
io
.
File
(
uploadBasePath
+
request
.
getFilename
());
FileInputStream
fis
=
new
FileInputStream
(
file
);
FileInputStream
fis
=
new
FileInputStream
(
file
);
byte
[]
buffer
=
new
byte
[
64
*
1024
];
// 64KB chunks
byte
[]
buffer
=
new
byte
[
64
*
1024
];
// 64KB chunks
int
bytesRead
;
int
bytesRead
;
//循环输入流,读取fis赋值给buffer,传输给客户端
while
((
bytesRead
=
fis
.
read
(
buffer
))
!=
-
1
)
{
while
((
bytesRead
=
fis
.
read
(
buffer
))
!=
-
1
)
{
responseObserver
.
onNext
(
FileDownloadResponse
.
newBuilder
()
responseObserver
.
onNext
(
FileDownloadResponse
.
newBuilder
()
.
setChunk
(
ByteString
.
copyFrom
(
buffer
,
0
,
bytesRead
))
.
setChunk
(
ByteString
.
copyFrom
(
buffer
,
0
,
bytesRead
))
...
...
ruoyi-admin/src/main/resources/application.yml
View file @
5b1541a6
...
@@ -47,6 +47,9 @@ user:
...
@@ -47,6 +47,9 @@ user:
# Spring配置
# Spring配置
spring
:
spring
:
# 引入项目自定义文件
config
:
import
:
"
optional:classpath:server-config.yml"
# 资源信息
# 资源信息
messages
:
messages
:
# 国际化资源文件路径
# 国际化资源文件路径
...
@@ -127,3 +130,5 @@ xss:
...
@@ -127,3 +130,5 @@ xss:
excludes
:
/system/notice
excludes
:
/system/notice
# 匹配链接
# 匹配链接
urlPatterns
:
/system/*,/monitor/*,/tool/*
urlPatterns
:
/system/*,/monitor/*,/tool/*
ruoyi-admin/src/main/resources/server-config.yml
0 → 100644
View file @
5b1541a6
server
:
upload
:
base_path
:
E:\server_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