From 731bb02a4b2ac70ab459bc32c12f2d39519da40c Mon Sep 17 00:00:00 2001 From: Ruurd Keizer Date: Wed, 17 Jan 2018 11:42:26 +0100 Subject: [PATCH] Automatically adjust part size on upload --- s3client.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/s3client.go b/s3client.go index 3655ee6e..6f948412 100644 --- a/s3client.go +++ b/s3client.go @@ -184,8 +184,18 @@ func (client *s3client) UploadFile(bucketName string, remotePath string, localPa } defer localFile.Close() + + // Automatically adjust partsize for larger files. + fSize := stat.Size() + if fSize > int64(uploader.MaxUploadParts) * uploader.PartSize { + partSize := fSize / int64(uploader.MaxUploadParts) + if fSize % int64(uploader.MaxUploadParts) != 0 { + partSize++ + } + uploader.PartSize = partSize + } - progress := client.newProgressBar(stat.Size()) + progress := client.newProgressBar(fSize) progress.Start() defer progress.Finish()