Skip to content

Commit

Permalink
修复由于变量作用域导致的分片上传的数据错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jsyzchen committed Feb 22, 2021
1 parent 7d37b46 commit b7244eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ func TestAccount_Quota(t *testing.T) {
if err != nil {
t.Fail()
}
t.Logf("TestAccount_UserInfo res: %+v", res)
t.Logf("TestAccount_Quota res: %+v", res)
}
11 changes: 5 additions & 6 deletions file/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (u *Uploader) Upload() (UploadResponse, error) {
return ret, err
}
defer file.Close()
buffer := make([]byte, sliceSize)
uploadRespChan := make(chan SuperFile2UploadResponse)
for i := 0; i < sliceNum; i++ {
buffer := make([]byte, sliceSize)
n, err := file.Read(buffer[:])
if err != nil && err != io.EOF {
log.Println("file.Read failed, err:", err)
Expand All @@ -127,13 +127,13 @@ func (u *Uploader) Upload() (UploadResponse, error) {
if n == 0 {
break
}
go func(partSeq int) {
uploadResp, err := u.SuperFile2Upload(uploadID, partSeq, buffer[0:n])
go func(partSeq int, partByte []byte) {
uploadResp, err := u.SuperFile2Upload(uploadID, partSeq, partByte)
uploadRespChan <- uploadResp
if err != nil {
log.Printf("SuperFile2UploadFailed, partseq[%d] err[%+v]", partSeq, err)
log.Printf("SuperFile2UploadFailed, partseq[%d] err[%v]", partSeq, err)
}
}(i)
}(i, buffer[0:n])
}

blockList := make([]string, sliceNum)
Expand Down Expand Up @@ -209,7 +209,6 @@ func (u *Uploader) PreCreate() (PreCreateResponse, error) {
body := v.Encode()

requestUrl := conf.OpenApiDomain + PreCreateUri + "&access_token=" + u.AccessToken

headers := make(map[string]string)
resp, err := httpclient.Post(requestUrl, headers, body)
if err != nil {
Expand Down

0 comments on commit b7244eb

Please sign in to comment.