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
89b2b532
Commit
89b2b532
authored
Apr 12, 2025
by
liuyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:优化代码
parent
795ebdd6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
10 deletions
+14
-10
FileServiceImpl.java
...c/main/java/com/ruoyi/client/service/FileServiceImpl.java
+14
-10
No files found.
ruoyi-admin/src/main/java/com/ruoyi/client/service/FileServiceImpl.java
View file @
89b2b532
...
...
@@ -2,6 +2,7 @@ package com.ruoyi.client.service;
import
com.google.protobuf.ByteString
;
import
com.ruoyi.grpc.file.*
;
import
io.grpc.Status
;
import
io.grpc.stub.StreamObserver
;
import
org.springframework.stereotype.Service
;
...
...
@@ -21,27 +22,27 @@ public class FileServiceImpl extends FileServiceGrpc.FileServiceImplBase {
@Override
public
void
onNext
(
FileUploadRequest
request
)
{
try
{
if
(
request
.
hasFilename
())
{
filename
=
request
.
getFilename
();
try
{
fos
=
new
FileOutputStream
(
"server_files/"
+
filename
);
}
catch
(
IOException
e
)
{
responseObserver
.
onError
(
e
);
}
fos
=
new
FileOutputStream
(
"E:\\server_file\\"
+
filename
);
}
else
{
try
{
byte
[]
chunk
=
request
.
getChunk
().
toByteArray
();
totalSize
+=
chunk
.
length
;
fos
.
write
(
chunk
);
}
catch
(
IOException
e
)
{
responseObserver
.
onError
(
e
);
}
}
catch
(
Exception
e
){
// 返回 INVALID_ARGUMENT 错误
responseObserver
.
onError
(
Status
.
INVALID_ARGUMENT
.
withDescription
(
"Upload failed:"
+
e
.
getMessage
())
.
withCause
(
e
)
.
asRuntimeException
());
}
}
@Override
public
void
onError
(
Throwable
t
)
{
System
.
err
.
println
(
"
Upload failed
: "
+
t
.
getMessage
());
System
.
err
.
println
(
"
客户端中断上传
: "
+
t
.
getMessage
());
}
@Override
...
...
@@ -54,7 +55,10 @@ public class FileServiceImpl extends FileServiceGrpc.FileServiceImplBase {
.
build
());
responseObserver
.
onCompleted
();
}
catch
(
IOException
e
)
{
responseObserver
.
onError
(
e
);
// 最终错误处理
responseObserver
.
onError
(
Status
.
INTERNAL
.
withDescription
(
"Finalization failed: "
+
e
.
getMessage
())
.
asRuntimeException
());
}
}
};
...
...
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