diff --git a/cmd/cmd_object.go b/cmd/cmd_object.go index eb8460e..820ec35 100644 --- a/cmd/cmd_object.go +++ b/cmd/cmd_object.go @@ -466,10 +466,14 @@ func uploadFile(bucketName, objectName, filePath, urlInfo string, ctx *cli.Conte defer reader.Close() progressReader := &ProgressReader{ - Reader: reader, - Total: objectSize, - StartTime: time.Now(), - LastPrinted: time.Now(), + Reader: reader, + Total: objectSize, + StartTime: time.Now(), + } + if objectSize > objectLargerSize { + progressReader.LastPrinted = time.Now().Add(time.Second * 2) + } else { + progressReader.LastPrinted = time.Now() } // if the file is more than 2G , it needs to force use resume uploading diff --git a/cmd/utils.go b/cmd/utils.go index f4e0a01..e935b80 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -105,6 +105,7 @@ const ( noBalanceErr = "key not found" maxListMemberNum = 1000 + objectLargerSize = 10 * 1024 * 1024 ) var ( @@ -541,10 +542,11 @@ func parseFileByArg(ctx *cli.Context, argIndex int) (int64, error) { type ProgressReader struct { io.Reader - Total int64 - Current int64 - StartTime time.Time - LastPrinted time.Time + Total int64 + Current int64 + StartTime time.Time + LastPrinted time.Time + LastPrintedStr string } func (pr *ProgressReader) Read(p []byte) (int, error) { @@ -561,8 +563,15 @@ func (pr *ProgressReader) printProgress() { uploadSpeed := float64(pr.Current) / elapsed.Seconds() if now.Sub(pr.LastPrinted) >= time.Second { // print rate every second - fmt.Printf("\ruploading progress: %.2f%% [ %s / %s ], rate: %10s", + progressStr := fmt.Sprintf("uploading progress: %.2f%% [ %s / %s ], rate: %s", progress, getConvertSize(pr.Current), getConvertSize(pr.Total), getConvertRate(uploadSpeed)) + + // Clear current line + fmt.Print("\r", strings.Repeat(" ", len(pr.LastPrintedStr)), "\r") + + // Print new progress + fmt.Print(progressStr) + pr.LastPrinted = now } }