From 97774c88d587165caf38ddb6a617a53a0a31fef9 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:58:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=20sftp=20=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=A4=A7=E6=96=87=E4=BB=B6=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#1294)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/utils/cloud_storage/client/sftp.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/utils/cloud_storage/client/sftp.go b/backend/utils/cloud_storage/client/sftp.go index 7f8d999a9..3a8232306 100644 --- a/backend/utils/cloud_storage/client/sftp.go +++ b/backend/utils/cloud_storage/client/sftp.go @@ -1,8 +1,8 @@ package client import ( + "bufio" "fmt" - "io" "net" "os" "path" @@ -75,11 +75,18 @@ func (s sftpClient) Upload(src, target string) (bool, error) { return false, err } defer dstFile.Close() - ff, err := io.ReadAll(srcFile) - if err != nil { - return false, err + + reader := bufio.NewReaderSize(srcFile, 128*1024*1024) + for { + chunk, err := reader.Peek(8 * 1024 * 1024) + if len(chunk) != 0 { + _, _ = dstFile.Write(chunk) + _, _ = reader.Discard(len(chunk)) + } + if err != nil { + break + } } - _, _ = dstFile.Write(ff) return true, nil }