Skip to content

Commit

Permalink
解决上传进度条异常的问题 (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellojukay committed Mar 23, 2022
1 parent 8bed923 commit 2403344
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api_file_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ func (r *FileService) UploadFile(ctx context.Context, request *UploadFileReq) (*
return nil, fmt.Errorf("unsupport dir upload")
}
if request.ShowProgressBar {
bar := progressbar.DefaultBytes(fileInfo.Size(), runewidth.FillRight(path.Base(fileInfo.Name()), 40))
bar := progressbar.NewOptions(
int(fileInfo.Size()),
progressbar.OptionSetWriter(os.Stdout),
progressbar.OptionSetDescription(runewidth.FillRight(path.Base(fileInfo.Name()), 40)),
progressbar.OptionOnCompletion(func() {
fmt.Printf("\n")
}),
)
reader := progressbar.NewReader(file, bar)
return r.UploadStream(ctx, request.DriveID, request.ParentID, path.Base(fileInfo.Name()), io.Reader(&reader), fileInfo.Size())
}
Expand Down

0 comments on commit 2403344

Please sign in to comment.