forked from felixonmars/BaiduPCS-Go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload2.go
65 lines (56 loc) · 1.32 KB
/
upload2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package pcsupload
/*
import (
"github.com/fzfile/BaiduPCS-Go/baidupcs"
)
type (
// PCSUpload2 新的上传方式
// TODO
PCSUpload2 struct {
pcs *baidupcs.BaiduPCS
targetPath string
uploadid string
}
)
func NewPCSUpload2(pcs *baidupcs.BaiduPCS, targetPath string) uploader.MultiUpload {
return &PCSUpload{
pcs: pcs,
targetPath: targetPath,
}
}
func (pu2 *PCSUpload2) lazyInit() {
if pu2.pcs == nil {
pu2.pcs = &baidupcs.BaiduPCS{}
}
}
// Precreate
func (pu2 *PCSUpload2) Precreate() (err error) {
return nil
}
func (pu2 *PCSUpload2) TmpFile(ctx context.Context, partseq int, partOffset int64, r rio.ReaderLen64) (checksum string, uperr error) {
pu2.lazyInit()
return pu.pcs.UploadTmpFile(func(uploadURL string, jar http.CookieJar) (resp *http.Response, err error) {
client := pcsconfig.Config.HTTPClient()
client.SetCookiejar(jar)
client.SetTimeout(0)
mr := multipartreader.NewMultipartReader()
mr.AddFormFile("uploadedfile", "", r)
mr.CloseMultipart()
doneChan := make(chan struct{}, 1)
go func() {
resp, err = client.Req("POST", uploadURL, mr, nil)
doneChan <- struct{}{}
}()
select {
case <-ctx.Done():
return resp, ctx.Err()
case <-doneChan:
// return
}
return
})
}
func (pu2 *PCSUpload2) CreateSuperFile(checksumList ...string) (err error) {
return nil
}
*/