@@ -144,8 +144,13 @@ type Uploader struct {
144144 // MaxUploadParts is the max number of parts which will be uploaded to S3.
145145 // Will be used to calculate the partsize of the object to be uploaded.
146146 // E.g: 5GB file, with MaxUploadParts set to 100, will upload the file
147- // as 100, 50MB parts.
148- // With a limited of s3.MaxUploadParts (10,000 parts).
147+ // as 100, 50MB parts. With a limited of s3.MaxUploadParts (10,000 parts).
148+ //
149+ // MaxUploadParts must not be used to limit the total number of bytes uploaded.
150+ // Use a type like to io.LimitReader (https://golang.org/pkg/io/#LimitedReader)
151+ // instead. An io.LimitReader is helpful when uploading an unbounded reader
152+ // to S3, and you know its maximum size. Otherwise the reader's io.EOF returned
153+ // error must be used to signal end of stream.
149154 MaxUploadParts int
150155
151156 // The client to use when uploading to S3.
@@ -532,21 +537,6 @@ func (u *multiuploader) upload(firstBuf io.ReadSeeker) (*UploadOutput, error) {
532537
533538 // Read and queue the rest of the parts
534539 for u .geterr () == nil && err == nil {
535- num ++
536- // This upload exceeded maximum number of supported parts, error now.
537- if num > int64 (u .cfg .MaxUploadParts ) || num > int64 (MaxUploadParts ) {
538- var msg string
539- if num > int64 (u .cfg .MaxUploadParts ) {
540- msg = fmt .Sprintf ("exceeded total allowed configured MaxUploadParts (%d). Adjust PartSize to fit in this limit" ,
541- u .cfg .MaxUploadParts )
542- } else {
543- msg = fmt .Sprintf ("exceeded total allowed S3 limit MaxUploadParts (%d). Adjust PartSize to fit in this limit" ,
544- MaxUploadParts )
545- }
546- u .seterr (awserr .New ("TotalPartsExceeded" , msg , nil ))
547- break
548- }
549-
550540 var reader io.ReadSeeker
551541 var nextChunkLen int
552542 reader , nextChunkLen , err = u .nextReader ()
@@ -566,6 +556,21 @@ func (u *multiuploader) upload(firstBuf io.ReadSeeker) (*UploadOutput, error) {
566556 break
567557 }
568558
559+ num ++
560+ // This upload exceeded maximum number of supported parts, error now.
561+ if num > int64 (u .cfg .MaxUploadParts ) || num > int64 (MaxUploadParts ) {
562+ var msg string
563+ if num > int64 (u .cfg .MaxUploadParts ) {
564+ msg = fmt .Sprintf ("exceeded total allowed configured MaxUploadParts (%d). Adjust PartSize to fit in this limit" ,
565+ u .cfg .MaxUploadParts )
566+ } else {
567+ msg = fmt .Sprintf ("exceeded total allowed S3 limit MaxUploadParts (%d). Adjust PartSize to fit in this limit" ,
568+ MaxUploadParts )
569+ }
570+ u .seterr (awserr .New ("TotalPartsExceeded" , msg , nil ))
571+ break
572+ }
573+
569574 ch <- chunk {buf : reader , num : num }
570575 }
571576
0 commit comments