@@ -3,6 +3,7 @@ package _139
3
3
import (
4
4
"context"
5
5
"encoding/base64"
6
+ "encoding/xml"
6
7
"fmt"
7
8
"io"
8
9
"net/http"
@@ -740,14 +741,20 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
740
741
break
741
742
}
742
743
}
744
+ var reportSize int64
745
+ if d .ReportRealSize {
746
+ reportSize = stream .GetSize ()
747
+ } else {
748
+ reportSize = 0
749
+ }
743
750
data := base.Json {
744
751
"manualRename" : 2 ,
745
752
"operation" : 0 ,
746
753
"fileCount" : 1 ,
747
- "totalSize" : 0 , // 去除上传大小限制
754
+ "totalSize" : reportSize ,
748
755
"uploadContentList" : []base.Json {{
749
756
"contentName" : stream .GetName (),
750
- "contentSize" : 0 , // 去除上传大小限制
757
+ "contentSize" : reportSize ,
751
758
// "digest": "5a3231986ce7a6b46e408612d385bafa"
752
759
}},
753
760
"parentCatalogID" : dstDir .GetID (),
@@ -765,10 +772,10 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
765
772
"operation" : 0 ,
766
773
"path" : path .Join (dstDir .GetPath (), dstDir .GetID ()),
767
774
"seqNo" : random .String (32 ), //序列号不能为空
768
- "totalSize" : 0 ,
775
+ "totalSize" : reportSize ,
769
776
"uploadContentList" : []base.Json {{
770
777
"contentName" : stream .GetName (),
771
- "contentSize" : 0 ,
778
+ "contentSize" : reportSize ,
772
779
// "digest": "5a3231986ce7a6b46e408612d385bafa"
773
780
}},
774
781
})
@@ -779,6 +786,9 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
779
786
if err != nil {
780
787
return err
781
788
}
789
+ if resp .Data .Result .ResultCode != "0" {
790
+ return fmt .Errorf ("get file upload url failed with result code: %s, message: %s" , resp .Data .Result .ResultCode , resp .Data .Result .ResultDesc )
791
+ }
782
792
783
793
// Progress
784
794
p := driver .NewProgress (stream .GetSize (), up )
@@ -820,13 +830,23 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
820
830
if err != nil {
821
831
return err
822
832
}
823
- _ = res .Body .Close ()
824
- log .Debugf ("%+v" , res )
825
833
if res .StatusCode != http .StatusOK {
834
+ res .Body .Close ()
826
835
return fmt .Errorf ("unexpected status code: %d" , res .StatusCode )
827
836
}
837
+ bodyBytes , err := io .ReadAll (res .Body )
838
+ if err != nil {
839
+ return fmt .Errorf ("error reading response body: %v" , err )
840
+ }
841
+ var result InterLayerUploadResult
842
+ err = xml .Unmarshal (bodyBytes , & result )
843
+ if err != nil {
844
+ return fmt .Errorf ("error parsing XML: %v" , err )
845
+ }
846
+ if result .ResultCode != 0 {
847
+ return fmt .Errorf ("upload failed with result code: %d, message: %s" , result .ResultCode , result .Msg )
848
+ }
828
849
}
829
-
830
850
return nil
831
851
default :
832
852
return errs .NotImplement
0 commit comments