Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SuperFile2Upload fails with empty response on high concurrency #16

Open
zmwangx opened this issue Apr 7, 2023 · 0 comments
Open

SuperFile2Upload fails with empty response on high concurrency #16

zmwangx opened this issue Apr 7, 2023 · 0 comments

Comments

@zmwangx
Copy link

zmwangx commented Apr 7, 2023

使用file.Uploader.Upload()时,我发现只要是几百MB及以上的文件100%失败,SuperFile2Upload返回空回复:

2023/04/07 13:32:14 upload failed, path[...] response[]
2023/04/07 13:32:14 SuperFile2UploadFailed, partseq[4] err[unexpected end of JSON input]
2023/04/07 13:32:14 strconv.Atoi failed, err: strconv.Atoi: parsing "": invalid syntax

把并发数调低之后就没问题了,1-3都行,别的没试:

diff --git a/file/upload.go b/file/upload.go
index 575f508..f787946 100644
--- a/file/upload.go
+++ b/file/upload.go
@@ -119,7 +119,7 @@ func (u *Uploader) Upload() (UploadResponse, error) {
 	}
 	defer file.Close()
 	uploadRespChan := make(chan SuperFile2UploadResponse, sliceNum)
-	sem := make(chan int, 10) //限制并发数,以防大文件上传导致占用服务器大量内存
+	sem := make(chan int, 3) //限制并发数,以防大文件上传导致占用服务器大量内存
 	for i := 0; i < sliceNum; i++ {
 		buffer := make([]byte, sliceSize)
 		n, err := file.Read(buffer[:])

第一次用百度网盘的API,也不知道是不是常见问题,反正记录一下方便遇到同样问题的朋友。我个人使用其实2并发也能完全占满上传带宽。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant