|
|
|
@ -25,6 +25,7 @@ type FileInfo struct { |
|
|
|
type FileChunk struct { |
|
|
|
Data []byte |
|
|
|
FileName string |
|
|
|
DirPath string |
|
|
|
Offset int64 |
|
|
|
IsLast bool |
|
|
|
} |
|
|
|
@ -107,6 +108,7 @@ func transferFile(c *UpFileClient, curPath string, uploadPath string) error { |
|
|
|
if reply != "true" { |
|
|
|
logger.Error("SendFileInfo failed", zap.String("reply", reply)) |
|
|
|
} |
|
|
|
fmt.Printf("SendFileInfo success, reply: %s\n", reply) |
|
|
|
|
|
|
|
// 打开文件准备读取
|
|
|
|
file, err := os.Open(curPath) |
|
|
|
@ -120,6 +122,9 @@ func transferFile(c *UpFileClient, curPath string, uploadPath string) error { |
|
|
|
reader := bufio.NewReader(file) |
|
|
|
var offset int64 = 0 |
|
|
|
|
|
|
|
// 目标文件目录
|
|
|
|
dirPath := filepath.Dir(uploadPath) |
|
|
|
|
|
|
|
fmt.Printf("开始发送文件: %s (大小: %d bytes)\n", fileName, fileInfo.Size()) |
|
|
|
|
|
|
|
var scReply bool |
|
|
|
@ -136,12 +141,14 @@ func transferFile(c *UpFileClient, curPath string, uploadPath string) error { |
|
|
|
err = c.rpcClient.Call("UpFileService.SendFileChunk", FileChunk{ |
|
|
|
Data: buffer[:n], |
|
|
|
FileName: fileName, |
|
|
|
DirPath: dirPath, |
|
|
|
Offset: offset, |
|
|
|
IsLast: isLast, |
|
|
|
}, &scReply) |
|
|
|
|
|
|
|
if err != nil || !scReply { |
|
|
|
panic("发送文件块失败: " + err.Error()) |
|
|
|
// panic("发送文件块失败: " + err.Error())
|
|
|
|
logger.Error("SendFileChunk failed", zap.Error(err)) |
|
|
|
} |
|
|
|
|
|
|
|
offset += int64(n) |
|
|
|
|