|
|
|
@ -58,27 +58,30 @@ func (f *UpFileService) SendFileInfo(info FileInfo, reply *string) error { |
|
|
|
|
|
|
|
// SendFileChunk 接收文件块并写入文件
|
|
|
|
func (f *UpFileService) SendFileChunk(chunk FileChunk, reply *bool) error { |
|
|
|
// filePath := filepath.Join("received_files", chunk.FileName)
|
|
|
|
// 日志
|
|
|
|
logger := util.NewProductionLogger() |
|
|
|
defer logger.Sync() |
|
|
|
filePath := filepath.Join("received_files", chunk.FileName) |
|
|
|
// fmt.Printf("recive file :%s", chunk.FileName)
|
|
|
|
// 合并为实际路径
|
|
|
|
// filePath := filepath.Join("received_files", chunk.FileName)
|
|
|
|
filePath := chunk.FileName |
|
|
|
// filePath := filepath.Join(dirPath, chunk.FileName)
|
|
|
|
// filePath := chunk.FileName
|
|
|
|
|
|
|
|
// 打开文件,使用追加模式
|
|
|
|
file, err := os.OpenFile(filePath, os.O_WRONLY, 0644) |
|
|
|
file, err := os.OpenFile(filePath, os.O_RDWR, 0644) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
logger.Error("SendFileChunk OpenFile failed", zap.Error(err)) |
|
|
|
} |
|
|
|
defer file.Close() |
|
|
|
|
|
|
|
// 移动到指定偏移量
|
|
|
|
if _, err := file.Seek(chunk.Offset, io.SeekStart); err != nil { |
|
|
|
return err |
|
|
|
logger.Error("SendFileChunk Seek failed", zap.Error(err)) |
|
|
|
} |
|
|
|
|
|
|
|
// 写入数据
|
|
|
|
if _, err := file.Write(chunk.Data); err != nil { |
|
|
|
return err |
|
|
|
logger.Error("SendFileChunk Write failed", zap.Error(err)) |
|
|
|
} |
|
|
|
|
|
|
|
*reply = true |
|
|
|
|