@@ -472,14 +472,16 @@ func (y *Cloud189PC) refreshSession() (err error) {
472
472
// 普通上传
473
473
// 无法上传大小为0的文件
474
474
func (y * Cloud189PC ) StreamUpload (ctx context.Context , dstDir model.Obj , file model.FileStreamer , up driver.UpdateProgress , isFamily bool , overwrite bool ) (model.Obj , error ) {
475
- size := file .GetSize ()
476
- sliceSize := min (size , partSize (size ))
475
+ // 文件大小
476
+ fileSize := file .GetSize ()
477
+ // 分片大小,不得为文件大小
478
+ sliceSize := partSize (fileSize )
477
479
478
480
params := Params {
479
481
"parentFolderId" : dstDir .GetID (),
480
482
"fileName" : url .QueryEscape (file .GetName ()),
481
- "fileSize" : fmt .Sprint (file . GetSize () ),
482
- "sliceSize" : fmt .Sprint (sliceSize ),
483
+ "fileSize" : fmt .Sprint (fileSize ),
484
+ "sliceSize" : fmt .Sprint (sliceSize ), // 必须为特定分片大小
483
485
"lazyCheck" : "1" ,
484
486
}
485
487
@@ -512,10 +514,10 @@ func (y *Cloud189PC) StreamUpload(ctx context.Context, dstDir model.Obj, file mo
512
514
retry .DelayType (retry .BackOffDelay ))
513
515
514
516
count := 1
515
- if size > sliceSize {
516
- count = int ((size + sliceSize - 1 ) / sliceSize )
517
+ if fileSize > sliceSize {
518
+ count = int ((fileSize + sliceSize - 1 ) / sliceSize )
517
519
}
518
- lastPartSize := size % sliceSize
520
+ lastPartSize := fileSize % sliceSize
519
521
if lastPartSize == 0 {
520
522
lastPartSize = sliceSize
521
523
}
@@ -535,9 +537,9 @@ func (y *Cloud189PC) StreamUpload(ctx context.Context, dstDir model.Obj, file mo
535
537
break
536
538
}
537
539
offset := int64 ((i )- 1 ) * sliceSize
538
- size := sliceSize
540
+ partSize := sliceSize
539
541
if i == count {
540
- size = lastPartSize
542
+ partSize = lastPartSize
541
543
}
542
544
partInfo := ""
543
545
var reader * stream.SectionReader
@@ -546,14 +548,14 @@ func (y *Cloud189PC) StreamUpload(ctx context.Context, dstDir model.Obj, file mo
546
548
Before : func (ctx context.Context ) error {
547
549
if reader == nil {
548
550
var err error
549
- reader , err = ss .GetSectionReader (offset , size )
551
+ reader , err = ss .GetSectionReader (offset , partSize )
550
552
if err != nil {
551
553
return err
552
554
}
553
555
silceMd5 .Reset ()
554
556
w , err := utils .CopyWithBuffer (writers , reader )
555
- if w != size {
556
- return fmt .Errorf ("failed to read all data: (expect =%d, actual =%d) %w" , size , w , err )
557
+ if w != partSize {
558
+ return fmt .Errorf ("failed to read all data: (expect =%d, actual =%d) %w" , partSize , w , err )
557
559
}
558
560
// 计算块md5并进行hex和base64编码
559
561
md5Bytes := silceMd5 .Sum (nil )
@@ -595,7 +597,7 @@ func (y *Cloud189PC) StreamUpload(ctx context.Context, dstDir model.Obj, file mo
595
597
fileMd5Hex = strings .ToUpper (hex .EncodeToString (fileMd5 .Sum (nil )))
596
598
}
597
599
sliceMd5Hex := fileMd5Hex
598
- if file . GetSize () > sliceSize {
600
+ if fileSize > sliceSize {
599
601
sliceMd5Hex = strings .ToUpper (utils .GetMD5EncodeStr (strings .Join (silceMd5Hexs , "\n " )))
600
602
}
601
603
0 commit comments