Skip to content

Commit

Permalink
fix upload failed
Browse files Browse the repository at this point in the history
  • Loading branch information
qjfoidnh committed Jan 7, 2025
1 parent b0684b5 commit d982495
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
4 changes: 1 addition & 3 deletions baidupcs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import (

const (
// MaxUploadBlockSize 最大上传的文件分片大小
MaxUploadBlockSize = 2 * converter.GB
MaxUploadBlockSize = 16 * converter.MB
// MinUploadBlockSize 最小的上传的文件分片大小
MinUploadBlockSize = 4 * converter.MB
// MaxRapidUploadSize 秒传文件支持的最大文件大小
MaxRapidUploadSize = 20 * converter.GB
// RecommendUploadBlockSize 推荐的上传的文件分片大小
RecommendUploadBlockSize = 1 * converter.GB
// SliceMD5Size 计算 slice-md5 所需的长度
SliceMD5Size = 256 * converter.KB
// EmptyContentMD5 空串的md5
Expand Down
6 changes: 3 additions & 3 deletions internal/pcsfunctions/pcsupload/upload_task_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type (
PCS *baidupcs.BaiduPCS
UploadingDatabase *UploadingDatabase // 数据库
Parallel int
NoRapidUpload bool // 禁用秒传
NoSplitFile bool // 禁用分片上传
NoRapidUpload bool // 禁用秒传
NoSplitFile bool // 禁用分片上传
Policy string // 上传重名文件策略

UploadStatistic *UploadStatistic
Expand All @@ -57,7 +57,7 @@ const (
)

const (
StrUploadFailed = "上传文件失败"
StrUploadFailed = "上传文件失败"
DefaultPrintFormat = "\r[%s] ↑ %s/%s %s/s in %s ............"
DefaultContentSize = 4 * converter.KB
)
Expand Down
16 changes: 9 additions & 7 deletions internal/pcsfunctions/pcsupload/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import (
"crypto/md5"
"fmt"
"github.com/qjfoidnh/BaiduPCS-Go/baidupcs"
"github.com/qjfoidnh/BaiduPCS-Go/pcsutil/converter"
"io"
"strconv"
)

func getBlockSize(fileSize int64) int64 {
blockNum := fileSize / baidupcs.MinUploadBlockSize
if blockNum > 999 {
return fileSize/999 + 1
blockSize := baidupcs.MinUploadBlockSize
if fileSize > 1*converter.GB && fileSize < 4*converter.GB {
blockSize = 2 * baidupcs.MinUploadBlockSize
} else if fileSize >= 4*converter.GB {
blockSize = baidupcs.MaxUploadBlockSize
}
return baidupcs.MinUploadBlockSize
return blockSize
}


func creaetDataOffset(contentMD5 string, uk, dataTime, fileSize, subSize int64) (offset int64, err error) {
h := md5.New()
ts := strconv.FormatInt(dataTime, 10)
Expand All @@ -27,10 +29,10 @@ func creaetDataOffset(contentMD5 string, uk, dataTime, fileSize, subSize int64)
if err != nil {
return
}
if fileSize - subSize + 1 <= 1 {
if fileSize-subSize+1 <= 1 {
offset = 0
return
}
offset = rawOffset % (fileSize - subSize + 1)
return
}
}
22 changes: 11 additions & 11 deletions requester/uploader/multiuploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ type (

// MultiUploaderConfig 多线程上传配置
MultiUploaderConfig struct {
Parallel int // 上传并发量
BlockSize int64 // 上传分块
MaxRate int64 // 限制最大上传速度
Policy string // 文件重名策略
Parallel int // 上传并发量
BlockSize int64 // 上传分块
MaxRate int64 // 限制最大上传速度
Policy string // 文件重名策略
}
)

Expand Down Expand Up @@ -85,7 +85,7 @@ func (muer *MultiUploader) lazyInit() {
muer.config.Parallel = 4
}
if muer.config.BlockSize <= 0 {
muer.config.BlockSize = 1 * converter.GB
muer.config.BlockSize = 16 * converter.MB
}
if muer.speedsStat == nil {
muer.speedsStat = &speeds.Speeds{}
Expand Down Expand Up @@ -167,32 +167,32 @@ func (muer *MultiUploader) Cancel() {
close(muer.canceled)
}

//OnExecute 设置开始上传事件
// OnExecute 设置开始上传事件
func (muer *MultiUploader) OnExecute(onExecuteEvent requester.Event) {
muer.onExecuteEvent = onExecuteEvent
}

//OnSuccess 设置成功上传事件
// OnSuccess 设置成功上传事件
func (muer *MultiUploader) OnSuccess(onSuccessEvent requester.Event) {
muer.onSuccessEvent = onSuccessEvent
}

//OnFinish 设置结束上传事件
// OnFinish 设置结束上传事件
func (muer *MultiUploader) OnFinish(onFinishEvent requester.Event) {
muer.onFinishEvent = onFinishEvent
}

//OnCancel 设置取消上传事件
// OnCancel 设置取消上传事件
func (muer *MultiUploader) OnCancel(onCancelEvent requester.Event) {
muer.onCancelEvent = onCancelEvent
}

//OnError 设置上传发生错误事件
// OnError 设置上传发生错误事件
func (muer *MultiUploader) OnError(onErrorEvent requester.EventOnError) {
muer.onErrorEvent = onErrorEvent
}

//OnUploadStatusEvent 设置上传状态事件
// OnUploadStatusEvent 设置上传状态事件
func (muer *MultiUploader) OnUploadStatusEvent(f UploadStatusFunc) {
muer.onUploadStatusEvent = f
}

0 comments on commit d982495

Please sign in to comment.